text
stringlengths
0
828
if not names and not wrongs:
names = sorted(m for m in available_cmaps if not m.endswith(""_r""))
return names"
1036,"def show_colormaps(names=[], N=10, show=True, use_qt=None):
""""""Function to show standard colormaps from pyplot
Parameters
----------
``*args``: str or :class:`matplotlib.colors.Colormap`
If a colormap, it returned unchanged.
%(cmap_note)s
N: int, optional
Default: 11. The number of increments in the colormap.
show: bool, optional
Default: True. If True, show the created figure at the end with
pyplot.show(block=False)
use_qt: bool
If True, use the
:class:`psy_simple.widgets.color.ColormapDialog.show_colormaps`, if
False use a matplotlib implementation based on [1]_. If None, use
the Qt implementation if it is running in the psyplot GUI.
Returns
-------
psy_simple.widgets.color.ColormapDialog or matplitlib.figure.Figure
Depending on `use_qt`, either an instance of the
:class:`psy_simple.widgets.color.ColormapDialog` or the
:class:`matplotlib.figure.Figure`
References
----------
.. [1] http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html
""""""
names = safe_list(names)
if use_qt or (use_qt is None and psyplot.with_gui):
from psy_simple.widgets.colors import ColormapDialog
from psyplot_gui.main import mainwindow
return ColormapDialog.show_colormap(names, N, show, parent=mainwindow)
import matplotlib.pyplot as plt
# This example comes from the Cookbook on www.scipy.org. According to the
# history, Andrew Straw did the conversion from an old page, but it is
# unclear who the original author is.
a = np.vstack((np.linspace(0, 1, 256).reshape(1, -1)))
# Get a list of the colormaps in matplotlib. Ignore the ones that end with
# '_r' because these are simply reversed versions of ones that don't end
# with '_r'
cmaps = _get_cmaps(names)
nargs = len(cmaps) + 1
fig = plt.figure(figsize=(5, 10))
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
for i, m in enumerate(cmaps):
ax = plt.subplot(nargs, 1, i+1)
plt.axis(""off"")
plt.pcolormesh(a, cmap=get_cmap(m, N + 1))
pos = list(ax.get_position().bounds)
fig.text(pos[0] - 0.01, pos[1], m, fontsize=10,
horizontalalignment='right')
fig.canvas.set_window_title(""Figure %i: Predefined colormaps"" % fig.number)
if show:
plt.show(block=False)
return fig"
1037,"def _create_stdout_logger(logging_level):
""""""
create a logger to stdout. This creates logger for a series
of module we would like to log information on.
""""""
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(logging.Formatter(
'[%(asctime)s] %(message)s', ""%H:%M:%S""
))
out_hdlr.setLevel(logging_level)
for name in LOGGING_NAMES:
log = logging.getLogger(name)
log.addHandler(out_hdlr)
log.setLevel(logging_level)"
1038,"def main():
""""""Generate a PDF using the async method.""""""
docraptor = DocRaptor()
print(""Create PDF"")
resp = docraptor.create(
{
""document_content"": ""<h1>python-docraptor</h1><p>Async Test</p>"",
""test"": True,
""async"": True,
}
)
print(""Status ID: {status_id}"".format(status_id=resp[""status_id""]))
status_id = resp[""status_id""]
resp = docraptor.status(status_id)
print("" {status}"".format(status=resp[""status""]))
while resp[""status""] != ""completed"":
time.sleep(3)
resp = docraptor.status(status_id)
print("" {status}"".format(status=resp[""status""]))
print(""Download to test_async.pdf"")
with open(""test_async.pdf"", ""wb"") as pdf_file: