From 040dd172d5f7fe5c8f7531089e6827145c5342e6 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sun, 4 Nov 2018 20:01:23 +0100 Subject: [PATCH 1/2] Add __all__ to pyplot --- lib/matplotlib/pyplot.py | 120 +++++++++++++++++++++++++++++++++++++++ tools/boilerplate.py | 16 ++++++ 2 files changed, 136 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 5a71207a2af7..54ef71be2c17 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -35,9 +35,105 @@ implicit and explicit interfaces. """ +__all__ = [ + 'Annotation', + 'Arrow', + 'Artist', + 'AutoLocator', + 'Axes', + 'Circle', + 'Figure', + 'FixedFormatter', + 'FixedLocator', + 'FormatStrFormatter', + 'Formatter', + 'FuncFormatter', + 'GridSpec', + 'IndexLocator', + 'Line2D', + 'LinearLocator', + 'Locator', + 'LogFormatter', + 'LogFormatterExponent', + 'LogFormatterMathtext', + 'LogLocator', + 'MaxNLocator', + 'MultipleLocator', + 'Normalize', + 'NullFormatter', + 'NullLocator', + 'PolarAxes', + 'Polygon', + 'Rectangle', + 'ScalarFormatter', + 'Subplot', + 'Text', + 'axes', + 'box', + 'cla', + 'clf', + 'clim', + 'close', + 'colorbar', + 'colormaps', + 'connect', + 'delaxes', + 'disconnect', + 'draw', + 'draw_all', + 'figimage', + 'figlegend', + 'fignum_exists', + 'figtext', + 'figure', + 'findobj', + 'gca', + 'gcf', + 'gci', + 'get_cmap', + 'get_figlabels', + 'get_fignums', + 'get_plot_commands', + 'ginput', + 'imread', + 'imsave', + 'ioff', + 'ion', + 'isinteractive', + 'matshow', + 'pause', + 'polar', + 'rc_context', + 'rgrids', + 'savefig', + 'sca', + 'set_cmap', + 'setp', + 'show', + 'subplot', + 'subplot2grid', + 'subplot_mosaic', + 'subplot_tool', + 'subplots', + 'subplots_adjust', + 'suptitle', + 'switch_backend', + 'thetagrids', + 'tight_layout', + 'twinx', + 'twiny', + 'waitforbuttonpress', + 'xkcd', + 'xlim', + 'xticks', + 'ylim', + 'yticks', +] # further expanded below with autogenerated functions + from contextlib import ExitStack from enum import Enum import functools + import importlib import inspect import logging @@ -3315,3 +3411,27 @@ def nipy_spectral(): image if there is one. See ``help(colormaps)`` for more information. """ set_cmap('nipy_spectral') + +__all__ += [ + 'acorr', 'angle_spectrum', 'annotate', 'arrow', 'autoscale', + 'axhline', 'axhspan', 'axis', 'axline', 'axvline', 'axvspan', 'bar', + 'barbs', 'barh', 'bar_label', 'boxplot', 'broken_barh', 'clabel', + 'cohere', 'contour', 'contourf', 'csd', 'errorbar', 'eventplot', + 'fill', 'fill_between', 'fill_betweenx', 'grid', 'hexbin', 'hist', + 'stairs', 'hist2d', 'hlines', 'imshow', 'legend', 'locator_params', + 'loglog', 'magnitude_spectrum', 'margins', 'minorticks_off', + 'minorticks_on', 'pcolor', 'pcolormesh', 'phase_spectrum', 'pie', + 'plot', 'plot_date', 'psd', 'quiver', 'quiverkey', 'scatter', + 'semilogx', 'semilogy', 'specgram', 'spy', 'stackplot', 'stem', + 'step', 'streamplot', 'table', 'text', 'tick_params', + 'ticklabel_format', 'tricontour', 'tricontourf', 'tripcolor', + 'triplot', 'violinplot', 'vlines', 'xcorr', 'sci', 'title', 'xlabel', + 'ylabel', 'xscale', 'yscale', 'figimage', 'figtext', 'gca', 'gci', + 'ginput', 'subplots_adjust', 'suptitle', 'tight_layout', + 'waitforbuttonpress', 'contour', 'contourf', 'hexbin', 'scatter', + 'pcolor', 'pcolormesh', 'hist2d', 'imshow', 'spy', 'quiver', + 'specgram', 'streamplot', 'tricontour', 'tricontourf', 'tripcolor', + 'autumn', 'bone', 'cool', 'copper', 'flag', 'gray', 'hot', 'hsv', + 'jet', 'pink', 'prism', 'spring', 'summer', 'winter', 'magma', + 'inferno', 'plasma', 'viridis', 'nipy_spectral' +] diff --git a/tools/boilerplate.py b/tools/boilerplate.py index 0b00d7a12b4a..697eea9ad9e2 100644 --- a/tools/boilerplate.py +++ b/tools/boilerplate.py @@ -16,6 +16,7 @@ from enum import Enum import inspect from inspect import Parameter +import itertools from pathlib import Path import sys import textwrap @@ -366,6 +367,21 @@ def boilerplate_gen(): yield AUTOGEN_MSG yield CMAP_TEMPLATE.format(name=name) + # extend __all__ + all_text_wrapper = textwrap.TextWrapper( + break_long_words=False, width=74, + initial_indent=' ' * 4, subsequent_indent=' ' * 4) + + t = all_text_wrapper.fill( + ', '.join([ + "'%s'" % funcname.split(':', 1)[0] + for funcname in itertools.chain( + _axes_commands, _figure_commands, cmappable, cmaps + )])) + + yield '\n' + yield '__all__ += [\n{}\n]\n'.format(t) + def build_pyplot(pyplot_path): pyplot_orig = pyplot_path.read_text().splitlines(keepends=True) From 1bc73528d69e26d4e5eb160bf134edeaecf8b882 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 9 Mar 2023 15:03:19 -0500 Subject: [PATCH 2/2] Generate pyplot wrappers at runtime This removes the need for a boilerplate and various templates that need to be generated and pass flake8. As a downside, the wrappers no longer ave explicit parameters, so argument errors are raised from the original methods, which may be confusing. --- lib/matplotlib/pyplot.py | 1304 +++++---------------------- lib/matplotlib/tests/test_pyplot.py | 33 - tools/boilerplate.py | 405 --------- 3 files changed, 241 insertions(+), 1501 deletions(-) delete mode 100644 tools/boilerplate.py diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 54ef71be2c17..1aee0fcf3fef 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1,6 +1,3 @@ -# Note: The first part of this file can be modified in place, but the latter -# part is autogenerated by the boilerplate.py script. - """ `matplotlib.pyplot` is a state-based interface to matplotlib. It provides an implicit, MATLAB-like, way of plotting. It also opens figures on your @@ -81,20 +78,15 @@ 'disconnect', 'draw', 'draw_all', - 'figimage', 'figlegend', 'fignum_exists', - 'figtext', 'figure', 'findobj', - 'gca', 'gcf', - 'gci', 'get_cmap', 'get_figlabels', 'get_fignums', 'get_plot_commands', - 'ginput', 'imread', 'imsave', 'ioff', @@ -115,14 +107,10 @@ 'subplot_mosaic', 'subplot_tool', 'subplots', - 'subplots_adjust', - 'suptitle', 'switch_backend', 'thetagrids', - 'tight_layout', 'twinx', 'twiny', - 'waitforbuttonpress', 'xkcd', 'xlim', 'xticks', @@ -160,7 +148,6 @@ from matplotlib.artist import Artist from matplotlib.axes import Axes, Subplot from matplotlib.projections import PolarAxes -from matplotlib import mlab # for detrend_none, window_hanning from matplotlib.scale import get_scale_names from matplotlib import cm @@ -1226,6 +1213,7 @@ def delaxes(ax=None): Remove an `~.axes.Axes` (defaulting to the current axes) from its figure. """ if ax is None: + gca = __getattr__('gca') ax = gca() ax.remove() @@ -1240,7 +1228,8 @@ def sca(ax): def cla(): """Clear the current axes.""" - # Not generated via boilerplate.py to allow a different docstring. + # Not generated via __getattr__ to allow a different docstring. + gca = __getattr__('gca') return gca().cla() @@ -1789,6 +1778,7 @@ def twinx(ax=None): :doc:`/gallery/subplots_axes_and_figures/two_scales` """ if ax is None: + gca = __getattr__('gca') ax = gca() ax1 = ax.twinx() return ax1 @@ -1805,6 +1795,7 @@ def twiny(ax=None): :doc:`/gallery/subplots_axes_and_figures/two_scales` """ if ax is None: + gca = __getattr__('gca') ax = gca() ax1 = ax.twiny() return ax1 @@ -1845,6 +1836,7 @@ def box(on=None): :meth:`matplotlib.axes.Axes.set_frame_on` :meth:`matplotlib.axes.Axes.get_frame_on` """ + gca = __getattr__('gca') ax = gca() if on is None: on = not ax.get_frame_on() @@ -1883,6 +1875,7 @@ def xlim(*args, **kwargs): Calling this function with arguments is the pyplot equivalent of calling `~.Axes.set_xlim` on the current axes. All arguments are passed though. """ + gca = __getattr__('gca') ax = gca() if not args and not kwargs: return ax.get_xlim() @@ -1920,6 +1913,7 @@ def ylim(*args, **kwargs): Calling this function with arguments is the pyplot equivalent of calling `~.Axes.set_ylim` on the current axes. All arguments are passed though. """ + gca = __getattr__('gca') ax = gca() if not args and not kwargs: return ax.get_ylim() @@ -1970,6 +1964,7 @@ def xticks(ticks=None, labels=None, *, minor=False, **kwargs): ... rotation=20) # Set text labels and properties. >>> xticks([]) # Disable xticks. """ + gca = __getattr__('gca') ax = gca() if ticks is None: @@ -2033,6 +2028,7 @@ def yticks(ticks=None, labels=None, *, minor=False, **kwargs): ... rotation=45) # Set text labels and properties. >>> yticks([]) # Disable yticks. """ + gca = __getattr__('gca') ax = gca() if ticks is None: @@ -2112,6 +2108,7 @@ def rgrids(radii=None, labels=None, angle=None, fmt=None, **kwargs): # set the locations and labels of the radial gridlines lines, labels = rgrids( (0.25, 0.5, 1.0), ('Tom', 'Dick', 'Harry' )) """ + gca = __getattr__('gca') ax = gca() if not isinstance(ax, PolarAxes): raise RuntimeError('rgrids only defined for polar axes') @@ -2180,6 +2177,7 @@ def thetagrids(angles=None, labels=None, fmt=None, **kwargs): # set the locations and labels of the angular gridlines lines, labels = thetagrids(range(45, 360, 90), ('NE', 'NW', 'SW', 'SE')) """ + gca = __getattr__('gca') ax = gca() if not isinstance(ax, PolarAxes): raise RuntimeError('thetagrids only defined for polar axes') @@ -2211,7 +2209,7 @@ def _get_pyplot_commands(): exclude = {'colormaps', 'colors', 'get_plot_commands', *colormaps} this_module = inspect.getmodule(get_plot_commands) return sorted( - name for name, obj in globals().items() + name for name, obj in inspect.getmembers(this_module) if not name.startswith('_') and name not in exclude and inspect.isfunction(obj) and inspect.getmodule(obj) is this_module) @@ -2223,6 +2221,7 @@ def _get_pyplot_commands(): @_copy_docstring_and_deprecators(Figure.colorbar) def colorbar(mappable=None, cax=None, ax=None, **kwargs): if mappable is None: + gci = __getattr__('gci') mappable = gci() if mappable is None: raise RuntimeError('No mappable was found to use for colorbar ' @@ -2247,6 +2246,7 @@ def clim(vmin=None, vmax=None): im.set_clim(0, 0.5) """ + gci = __getattr__('gci') im = gci() if im is None: raise RuntimeError('You must first define an image, e.g., with imshow') @@ -2279,6 +2279,7 @@ def set_cmap(cmap): cmap = get_cmap(cmap) rc('image', cmap=cmap.name) + gci = __getattr__('gci') im = gci() if im is not None: @@ -2336,6 +2337,7 @@ def matshow(A, fignum=None, **kwargs): """ A = np.asanyarray(A) if fignum == 0: + gca = __getattr__('gca') ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized @@ -2343,6 +2345,7 @@ def matshow(A, fignum=None, **kwargs): fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) + sci = __getattr__('sci') sci(im) return im @@ -2360,6 +2363,7 @@ def polar(*args, **kwargs): """ # If an axis already exists, check if it has a polar projection if gcf().get_axes(): + gca = __getattr__('gca') ax = gca() if not isinstance(ax, PolarAxes): _api.warn_external('Trying to create polar plot on an Axes ' @@ -2379,1059 +2383,233 @@ def polar(*args, **kwargs): rcParams._set("backend", rcsetup._auto_backend_sentinel) -################# REMAINING CONTENT GENERATED BY boilerplate.py ############## - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.figimage) -def figimage( - X, xo=0, yo=0, alpha=None, norm=None, cmap=None, vmin=None, - vmax=None, origin=None, resize=False, **kwargs): - return gcf().figimage( - X, xo=xo, yo=yo, alpha=alpha, norm=norm, cmap=cmap, vmin=vmin, - vmax=vmax, origin=origin, resize=resize, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.text) -def figtext(x, y, s, fontdict=None, **kwargs): - return gcf().text(x, y, s, fontdict=fontdict, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.gca) -def gca(): - return gcf().gca() - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure._gci) -def gci(): - return gcf()._gci() - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.ginput) -def ginput( - n=1, timeout=30, show_clicks=True, - mouse_add=MouseButton.LEFT, mouse_pop=MouseButton.RIGHT, - mouse_stop=MouseButton.MIDDLE): - return gcf().ginput( - n=n, timeout=timeout, show_clicks=show_clicks, - mouse_add=mouse_add, mouse_pop=mouse_pop, - mouse_stop=mouse_stop) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.subplots_adjust) -def subplots_adjust( - left=None, bottom=None, right=None, top=None, wspace=None, - hspace=None): - return gcf().subplots_adjust( - left=left, bottom=bottom, right=right, top=top, wspace=wspace, - hspace=hspace) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.suptitle) -def suptitle(t, **kwargs): - return gcf().suptitle(t, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.tight_layout) -def tight_layout(*, pad=1.08, h_pad=None, w_pad=None, rect=None): - return gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Figure.waitforbuttonpress) -def waitforbuttonpress(timeout=-1): - return gcf().waitforbuttonpress(timeout=timeout) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.acorr) -def acorr(x, *, data=None, **kwargs): - return gca().acorr( - x, **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.angle_spectrum) -def angle_spectrum( - x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, *, - data=None, **kwargs): - return gca().angle_spectrum( - x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.annotate) -def annotate( - text, xy, xytext=None, xycoords='data', textcoords=None, - arrowprops=None, annotation_clip=None, **kwargs): - return gca().annotate( - text, xy, xytext=xytext, xycoords=xycoords, - textcoords=textcoords, arrowprops=arrowprops, - annotation_clip=annotation_clip, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.arrow) -def arrow(x, y, dx, dy, **kwargs): - return gca().arrow(x, y, dx, dy, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.autoscale) -def autoscale(enable=True, axis='both', tight=None): - return gca().autoscale(enable=enable, axis=axis, tight=tight) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axhline) -def axhline(y=0, xmin=0, xmax=1, **kwargs): - return gca().axhline(y=y, xmin=xmin, xmax=xmax, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axhspan) -def axhspan(ymin, ymax, xmin=0, xmax=1, **kwargs): - return gca().axhspan(ymin, ymax, xmin=xmin, xmax=xmax, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axis) -def axis(arg=None, /, *, emit=True, **kwargs): - return gca().axis(arg, emit=emit, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axline) -def axline(xy1, xy2=None, *, slope=None, **kwargs): - return gca().axline(xy1, xy2=xy2, slope=slope, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axvline) -def axvline(x=0, ymin=0, ymax=1, **kwargs): - return gca().axvline(x=x, ymin=ymin, ymax=ymax, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.axvspan) -def axvspan(xmin, xmax, ymin=0, ymax=1, **kwargs): - return gca().axvspan(xmin, xmax, ymin=ymin, ymax=ymax, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.bar) -def bar( - x, height, width=0.8, bottom=None, *, align='center', - data=None, **kwargs): - return gca().bar( - x, height, width=width, bottom=bottom, align=align, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.barbs) -def barbs(*args, data=None, **kwargs): - return gca().barbs( - *args, **({"data": data} if data is not None else {}), - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.barh) -def barh( - y, width, height=0.8, left=None, *, align='center', - data=None, **kwargs): - return gca().barh( - y, width, height=height, left=left, align=align, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.bar_label) -def bar_label( - container, labels=None, *, fmt='%g', label_type='edge', - padding=0, **kwargs): - return gca().bar_label( - container, labels=labels, fmt=fmt, label_type=label_type, - padding=padding, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.boxplot) -def boxplot( - x, notch=None, sym=None, vert=None, whis=None, - positions=None, widths=None, patch_artist=None, - bootstrap=None, usermedians=None, conf_intervals=None, - meanline=None, showmeans=None, showcaps=None, showbox=None, - showfliers=None, boxprops=None, labels=None, flierprops=None, - medianprops=None, meanprops=None, capprops=None, - whiskerprops=None, manage_ticks=True, autorange=False, - zorder=None, capwidths=None, *, data=None): - return gca().boxplot( - x, notch=notch, sym=sym, vert=vert, whis=whis, - positions=positions, widths=widths, patch_artist=patch_artist, - bootstrap=bootstrap, usermedians=usermedians, - conf_intervals=conf_intervals, meanline=meanline, - showmeans=showmeans, showcaps=showcaps, showbox=showbox, - showfliers=showfliers, boxprops=boxprops, labels=labels, - flierprops=flierprops, medianprops=medianprops, - meanprops=meanprops, capprops=capprops, - whiskerprops=whiskerprops, manage_ticks=manage_ticks, - autorange=autorange, zorder=zorder, capwidths=capwidths, - **({"data": data} if data is not None else {})) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.broken_barh) -def broken_barh(xranges, yrange, *, data=None, **kwargs): - return gca().broken_barh( - xranges, yrange, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.clabel) -def clabel(CS, levels=None, **kwargs): - return gca().clabel(CS, levels=levels, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.cohere) -def cohere( - x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, - window=mlab.window_hanning, noverlap=0, pad_to=None, - sides='default', scale_by_freq=None, *, data=None, **kwargs): - return gca().cohere( - x, y, NFFT=NFFT, Fs=Fs, Fc=Fc, detrend=detrend, window=window, - noverlap=noverlap, pad_to=pad_to, sides=sides, - scale_by_freq=scale_by_freq, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.contour) -def contour(*args, data=None, **kwargs): - __ret = gca().contour( - *args, **({"data": data} if data is not None else {}), - **kwargs) - if __ret._A is not None: sci(__ret) # noqa - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.contourf) -def contourf(*args, data=None, **kwargs): - __ret = gca().contourf( - *args, **({"data": data} if data is not None else {}), - **kwargs) - if __ret._A is not None: sci(__ret) # noqa - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.csd) -def csd( - x, y, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, - noverlap=None, pad_to=None, sides=None, scale_by_freq=None, - return_line=None, *, data=None, **kwargs): - return gca().csd( - x, y, NFFT=NFFT, Fs=Fs, Fc=Fc, detrend=detrend, window=window, - noverlap=noverlap, pad_to=pad_to, sides=sides, - scale_by_freq=scale_by_freq, return_line=return_line, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.errorbar) -def errorbar( - x, y, yerr=None, xerr=None, fmt='', ecolor=None, - elinewidth=None, capsize=None, barsabove=False, lolims=False, - uplims=False, xlolims=False, xuplims=False, errorevery=1, - capthick=None, *, data=None, **kwargs): - return gca().errorbar( - x, y, yerr=yerr, xerr=xerr, fmt=fmt, ecolor=ecolor, - elinewidth=elinewidth, capsize=capsize, barsabove=barsabove, - lolims=lolims, uplims=uplims, xlolims=xlolims, - xuplims=xuplims, errorevery=errorevery, capthick=capthick, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.eventplot) -def eventplot( - positions, orientation='horizontal', lineoffsets=1, - linelengths=1, linewidths=None, colors=None, alpha=None, - linestyles='solid', *, data=None, **kwargs): - return gca().eventplot( - positions, orientation=orientation, lineoffsets=lineoffsets, - linelengths=linelengths, linewidths=linewidths, colors=colors, - alpha=alpha, linestyles=linestyles, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.fill) -def fill(*args, data=None, **kwargs): - return gca().fill( - *args, **({"data": data} if data is not None else {}), - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.fill_between) -def fill_between( - x, y1, y2=0, where=None, interpolate=False, step=None, *, - data=None, **kwargs): - return gca().fill_between( - x, y1, y2=y2, where=where, interpolate=interpolate, step=step, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.fill_betweenx) -def fill_betweenx( - y, x1, x2=0, where=None, step=None, interpolate=False, *, - data=None, **kwargs): - return gca().fill_betweenx( - y, x1, x2=x2, where=where, step=step, interpolate=interpolate, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.grid) -def grid(visible=None, which='major', axis='both', **kwargs): - return gca().grid(visible=visible, which=which, axis=axis, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.hexbin) -def hexbin( - x, y, C=None, gridsize=100, bins=None, xscale='linear', - yscale='linear', extent=None, cmap=None, norm=None, vmin=None, - vmax=None, alpha=None, linewidths=None, edgecolors='face', - reduce_C_function=np.mean, mincnt=None, marginals=False, *, - data=None, **kwargs): - __ret = gca().hexbin( - x, y, C=C, gridsize=gridsize, bins=bins, xscale=xscale, - yscale=yscale, extent=extent, cmap=cmap, norm=norm, vmin=vmin, - vmax=vmax, alpha=alpha, linewidths=linewidths, - edgecolors=edgecolors, reduce_C_function=reduce_C_function, - mincnt=mincnt, marginals=marginals, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.hist) -def hist( - x, bins=None, range=None, density=False, weights=None, - cumulative=False, bottom=None, histtype='bar', align='mid', - orientation='vertical', rwidth=None, log=False, color=None, - label=None, stacked=False, *, data=None, **kwargs): - return gca().hist( - x, bins=bins, range=range, density=density, weights=weights, - cumulative=cumulative, bottom=bottom, histtype=histtype, - align=align, orientation=orientation, rwidth=rwidth, log=log, - color=color, label=label, stacked=stacked, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.stairs) -def stairs( - values, edges=None, *, orientation='vertical', baseline=0, - fill=False, data=None, **kwargs): - return gca().stairs( - values, edges=edges, orientation=orientation, - baseline=baseline, fill=fill, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.hist2d) -def hist2d( - x, y, bins=10, range=None, density=False, weights=None, - cmin=None, cmax=None, *, data=None, **kwargs): - __ret = gca().hist2d( - x, y, bins=bins, range=range, density=density, - weights=weights, cmin=cmin, cmax=cmax, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret[-1]) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.hlines) -def hlines( - y, xmin, xmax, colors=None, linestyles='solid', label='', *, - data=None, **kwargs): - return gca().hlines( - y, xmin, xmax, colors=colors, linestyles=linestyles, - label=label, **({"data": data} if data is not None else {}), - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.imshow) -def imshow( - X, cmap=None, norm=None, *, aspect=None, interpolation=None, - alpha=None, vmin=None, vmax=None, origin=None, extent=None, - interpolation_stage=None, filternorm=True, filterrad=4.0, - resample=None, url=None, data=None, **kwargs): - __ret = gca().imshow( - X, cmap=cmap, norm=norm, aspect=aspect, - interpolation=interpolation, alpha=alpha, vmin=vmin, - vmax=vmax, origin=origin, extent=extent, - interpolation_stage=interpolation_stage, - filternorm=filternorm, filterrad=filterrad, resample=resample, - url=url, **({"data": data} if data is not None else {}), - **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.legend) -def legend(*args, **kwargs): - return gca().legend(*args, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.locator_params) -def locator_params(axis='both', tight=None, **kwargs): - return gca().locator_params(axis=axis, tight=tight, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.loglog) -def loglog(*args, **kwargs): - return gca().loglog(*args, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.magnitude_spectrum) -def magnitude_spectrum( - x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, - scale=None, *, data=None, **kwargs): - return gca().magnitude_spectrum( - x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, - scale=scale, **({"data": data} if data is not None else {}), - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.margins) -def margins(*margins, x=None, y=None, tight=True): - return gca().margins(*margins, x=x, y=y, tight=tight) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.minorticks_off) -def minorticks_off(): - return gca().minorticks_off() - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.minorticks_on) -def minorticks_on(): - return gca().minorticks_on() - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.pcolor) -def pcolor( - *args, shading=None, alpha=None, norm=None, cmap=None, - vmin=None, vmax=None, data=None, **kwargs): - __ret = gca().pcolor( - *args, shading=shading, alpha=alpha, norm=norm, cmap=cmap, - vmin=vmin, vmax=vmax, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.pcolormesh) -def pcolormesh( - *args, alpha=None, norm=None, cmap=None, vmin=None, - vmax=None, shading=None, antialiased=False, data=None, - **kwargs): - __ret = gca().pcolormesh( - *args, alpha=alpha, norm=norm, cmap=cmap, vmin=vmin, - vmax=vmax, shading=shading, antialiased=antialiased, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.phase_spectrum) -def phase_spectrum( - x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, *, - data=None, **kwargs): - return gca().phase_spectrum( - x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.pie) -def pie( - x, explode=None, labels=None, colors=None, autopct=None, - pctdistance=0.6, shadow=False, labeldistance=1.1, - startangle=0, radius=1, counterclock=True, wedgeprops=None, - textprops=None, center=(0, 0), frame=False, - rotatelabels=False, *, normalize=True, hatch=None, data=None): - return gca().pie( - x, explode=explode, labels=labels, colors=colors, - autopct=autopct, pctdistance=pctdistance, shadow=shadow, - labeldistance=labeldistance, startangle=startangle, - radius=radius, counterclock=counterclock, - wedgeprops=wedgeprops, textprops=textprops, center=center, - frame=frame, rotatelabels=rotatelabels, normalize=normalize, - hatch=hatch, **({"data": data} if data is not None else {})) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.plot) -def plot(*args, scalex=True, scaley=True, data=None, **kwargs): - return gca().plot( - *args, scalex=scalex, scaley=scaley, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.plot_date) -def plot_date( - x, y, fmt='o', tz=None, xdate=True, ydate=False, *, - data=None, **kwargs): - return gca().plot_date( - x, y, fmt=fmt, tz=tz, xdate=xdate, ydate=ydate, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.psd) -def psd( - x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, - noverlap=None, pad_to=None, sides=None, scale_by_freq=None, - return_line=None, *, data=None, **kwargs): - return gca().psd( - x, NFFT=NFFT, Fs=Fs, Fc=Fc, detrend=detrend, window=window, - noverlap=noverlap, pad_to=pad_to, sides=sides, - scale_by_freq=scale_by_freq, return_line=return_line, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.quiver) -def quiver(*args, data=None, **kwargs): - __ret = gca().quiver( - *args, **({"data": data} if data is not None else {}), - **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.quiverkey) -def quiverkey(Q, X, Y, U, label, **kwargs): - return gca().quiverkey(Q, X, Y, U, label, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.scatter) -def scatter( - x, y, s=None, c=None, marker=None, cmap=None, norm=None, - vmin=None, vmax=None, alpha=None, linewidths=None, *, - edgecolors=None, plotnonfinite=False, data=None, **kwargs): - __ret = gca().scatter( - x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm, - vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths, - edgecolors=edgecolors, plotnonfinite=plotnonfinite, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.semilogx) -def semilogx(*args, **kwargs): - return gca().semilogx(*args, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.semilogy) -def semilogy(*args, **kwargs): - return gca().semilogy(*args, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.specgram) -def specgram( - x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, - noverlap=None, cmap=None, xextent=None, pad_to=None, - sides=None, scale_by_freq=None, mode=None, scale=None, - vmin=None, vmax=None, *, data=None, **kwargs): - __ret = gca().specgram( - x, NFFT=NFFT, Fs=Fs, Fc=Fc, detrend=detrend, window=window, - noverlap=noverlap, cmap=cmap, xextent=xextent, pad_to=pad_to, - sides=sides, scale_by_freq=scale_by_freq, mode=mode, - scale=scale, vmin=vmin, vmax=vmax, - **({"data": data} if data is not None else {}), **kwargs) - sci(__ret[-1]) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.spy) -def spy( - Z, precision=0, marker=None, markersize=None, aspect='equal', - origin='upper', **kwargs): - __ret = gca().spy( - Z, precision=precision, marker=marker, markersize=markersize, - aspect=aspect, origin=origin, **kwargs) - if isinstance(__ret, cm.ScalarMappable): sci(__ret) # noqa - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.stackplot) -def stackplot( - x, *args, labels=(), colors=None, baseline='zero', data=None, - **kwargs): - return gca().stackplot( - x, *args, labels=labels, colors=colors, baseline=baseline, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.stem) -def stem( - *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, - label=None, orientation='vertical', data=None): - return gca().stem( - *args, linefmt=linefmt, markerfmt=markerfmt, basefmt=basefmt, - bottom=bottom, label=label, orientation=orientation, - **({"data": data} if data is not None else {})) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.step) -def step(x, y, *args, where='pre', data=None, **kwargs): - return gca().step( - x, y, *args, where=where, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.streamplot) -def streamplot( - x, y, u, v, density=1, linewidth=None, color=None, cmap=None, - norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1, - transform=None, zorder=None, start_points=None, maxlength=4.0, - integration_direction='both', broken_streamlines=True, *, - data=None): - __ret = gca().streamplot( - x, y, u, v, density=density, linewidth=linewidth, color=color, - cmap=cmap, norm=norm, arrowsize=arrowsize, - arrowstyle=arrowstyle, minlength=minlength, - transform=transform, zorder=zorder, start_points=start_points, - maxlength=maxlength, - integration_direction=integration_direction, - broken_streamlines=broken_streamlines, - **({"data": data} if data is not None else {})) - sci(__ret.lines) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.table) -def table( - cellText=None, cellColours=None, cellLoc='right', - colWidths=None, rowLabels=None, rowColours=None, - rowLoc='left', colLabels=None, colColours=None, - colLoc='center', loc='bottom', bbox=None, edges='closed', - **kwargs): - return gca().table( - cellText=cellText, cellColours=cellColours, cellLoc=cellLoc, - colWidths=colWidths, rowLabels=rowLabels, - rowColours=rowColours, rowLoc=rowLoc, colLabels=colLabels, - colColours=colColours, colLoc=colLoc, loc=loc, bbox=bbox, - edges=edges, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.text) -def text(x, y, s, fontdict=None, **kwargs): - return gca().text(x, y, s, fontdict=fontdict, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.tick_params) -def tick_params(axis='both', **kwargs): - return gca().tick_params(axis=axis, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.ticklabel_format) -def ticklabel_format( - *, axis='both', style='', scilimits=None, useOffset=None, - useLocale=None, useMathText=None): - return gca().ticklabel_format( - axis=axis, style=style, scilimits=scilimits, - useOffset=useOffset, useLocale=useLocale, - useMathText=useMathText) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.tricontour) -def tricontour(*args, **kwargs): - __ret = gca().tricontour(*args, **kwargs) - if __ret._A is not None: sci(__ret) # noqa - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.tricontourf) -def tricontourf(*args, **kwargs): - __ret = gca().tricontourf(*args, **kwargs) - if __ret._A is not None: sci(__ret) # noqa - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.tripcolor) -def tripcolor( - *args, alpha=1.0, norm=None, cmap=None, vmin=None, vmax=None, - shading='flat', facecolors=None, **kwargs): - __ret = gca().tripcolor( - *args, alpha=alpha, norm=norm, cmap=cmap, vmin=vmin, - vmax=vmax, shading=shading, facecolors=facecolors, **kwargs) - sci(__ret) - return __ret - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.triplot) -def triplot(*args, **kwargs): - return gca().triplot(*args, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.violinplot) -def violinplot( - dataset, positions=None, vert=True, widths=0.5, - showmeans=False, showextrema=True, showmedians=False, - quantiles=None, points=100, bw_method=None, *, data=None): - return gca().violinplot( - dataset, positions=positions, vert=vert, widths=widths, - showmeans=showmeans, showextrema=showextrema, - showmedians=showmedians, quantiles=quantiles, points=points, - bw_method=bw_method, - **({"data": data} if data is not None else {})) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.vlines) -def vlines( - x, ymin, ymax, colors=None, linestyles='solid', label='', *, - data=None, **kwargs): - return gca().vlines( - x, ymin, ymax, colors=colors, linestyles=linestyles, - label=label, **({"data": data} if data is not None else {}), - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.xcorr) -def xcorr( - x, y, normed=True, detrend=mlab.detrend_none, usevlines=True, - maxlags=10, *, data=None, **kwargs): - return gca().xcorr( - x, y, normed=normed, detrend=detrend, usevlines=usevlines, - maxlags=maxlags, - **({"data": data} if data is not None else {}), **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes._sci) -def sci(im): - return gca()._sci(im) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.set_title) -def title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs): - return gca().set_title( - label, fontdict=fontdict, loc=loc, pad=pad, y=y, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.set_xlabel) -def xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs): - return gca().set_xlabel( - xlabel, fontdict=fontdict, labelpad=labelpad, loc=loc, - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.set_ylabel) -def ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs): - return gca().set_ylabel( - ylabel, fontdict=fontdict, labelpad=labelpad, loc=loc, - **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.set_xscale) -def xscale(value, **kwargs): - return gca().set_xscale(value, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_copy_docstring_and_deprecators(Axes.set_yscale) -def yscale(value, **kwargs): - return gca().set_yscale(value, **kwargs) - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def autumn(): - """ - Set the colormap to 'autumn'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('autumn') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def bone(): - """ - Set the colormap to 'bone'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('bone') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def cool(): - """ - Set the colormap to 'cool'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('cool') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def copper(): - """ - Set the colormap to 'copper'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('copper') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def flag(): - """ - Set the colormap to 'flag'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('flag') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def gray(): - """ - Set the colormap to 'gray'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('gray') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def hot(): - """ - Set the colormap to 'hot'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('hot') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def hsv(): - """ - Set the colormap to 'hsv'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('hsv') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def jet(): - """ - Set the colormap to 'jet'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('jet') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def pink(): - """ - Set the colormap to 'pink'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('pink') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def prism(): - """ - Set the colormap to 'prism'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('prism') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def spring(): - """ - Set the colormap to 'spring'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('spring') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def summer(): - """ - Set the colormap to 'summer'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('summer') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def winter(): - """ - Set the colormap to 'winter'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('winter') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def magma(): - """ - Set the colormap to 'magma'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('magma') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def inferno(): - """ - Set the colormap to 'inferno'. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('inferno') - - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def plasma(): - """ - Set the colormap to 'plasma'. +# These methods are all simple wrappers of Figure methods with the name given in the +# dictionary value, or by the same name, if the value is None. +_figure_commands = { + 'figimage': None, + 'figtext': 'text', + 'gca': None, + 'gci': '_gci', + 'ginput': None, + 'subplots_adjust': None, + 'suptitle': None, + 'tight_layout': None, + 'waitforbuttonpress': None, +} +# These methods are all simple wrappers of Axes methods by the same name. +_axes_commands = { + 'acorr': None, + 'angle_spectrum': None, + 'annotate': None, + 'arrow': None, + 'autoscale': None, + 'axhline': None, + 'axhspan': None, + 'axis': None, + 'axline': None, + 'axvline': None, + 'axvspan': None, + 'bar': None, + 'bar_label': None, + 'barbs': None, + 'barh': None, + 'boxplot': None, + 'broken_barh': None, + 'clabel': None, + 'cohere': None, + 'contour': None, + 'contourf': None, + 'csd': None, + 'errorbar': None, + 'eventplot': None, + 'fill': None, + 'fill_between': None, + 'fill_betweenx': None, + 'grid': None, + 'hexbin': None, + 'hist': None, + 'hist2d': None, + 'hlines': None, + 'imshow': None, + 'legend': None, + 'locator_params': None, + 'loglog': None, + 'magnitude_spectrum': None, + 'margins': None, + 'minorticks_off': None, + 'minorticks_on': None, + 'pcolor': None, + 'pcolormesh': None, + 'phase_spectrum': None, + 'pie': None, + 'plot': None, + 'plot_date': None, + 'psd': None, + 'quiver': None, + 'quiverkey': None, + 'scatter': None, + 'semilogx': None, + 'semilogy': None, + 'specgram': None, + 'spy': None, + 'stackplot': None, + 'stairs': None, + 'stem': None, + 'step': None, + 'streamplot': None, + 'table': None, + 'text': None, + 'tick_params': None, + 'ticklabel_format': None, + 'tricontour': None, + 'tricontourf': None, + 'tripcolor': None, + 'triplot': None, + 'violinplot': None, + 'vlines': None, + 'xcorr': None, + # pyplot name : real name + 'sci': '_sci', + 'title': 'set_title', + 'xlabel': 'set_xlabel', + 'xscale': 'set_xscale', + 'ylabel': 'set_ylabel', + 'yscale': 'set_yscale', +} +_cmaps = ( + 'autumn', + 'bone', + 'cool', + 'copper', + 'flag', + 'gray', + 'hot', + 'hsv', + 'inferno', + 'jet', + 'magma', + 'nipy_spectral', + 'pink', + 'plasma', + 'prism', + 'spring', + 'summer', + 'viridis', + 'winter', +) + +__all__ += [*_figure_commands, *_axes_commands, *_cmaps] + + +def __dir__(): + return __all__ + [ + 'draw_if_interactive', + 'get', + 'get_current_fig_manager', + 'getp', + 'install_repl_displayhook', + 'new_figure_manager', + 'rc', + 'rcdefaults', + 'set_loglevel', + 'uninstall_repl_displayhook', + ] + + +def _make_pyplot_wrapper(method, name, func=None): + # Like functools.wraps, but keeps the wrapper living in this file, as a + # standalone function. Also applies _copy_docstring_and_deprecators for + # deprecations. + if func is None: + return functools.partial(_make_pyplot_wrapper, method, name) + functools.update_wrapper(func, method, assigned=('__annotations__', '__doc__')) + func = _copy_docstring_and_deprecators(method)(func) + func.__module__ = 'matplotlib.pyplot' + func.__name__ = func.__qualname__ = name + signature = inspect.signature(method) + params = list(signature.parameters.values())[1:] # Drop self argument. + func.__signature__ = signature.replace(parameters=params) + return func - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('plasma') +@functools.cache +def __getattr__(name): + if name in _figure_commands: + called_name = _figure_commands[name] or name + method = getattr(Figure, called_name) + + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + return getattr(gcf(), called_name)(*args, **kwargs) + + return _pyplot_wrapper + + elif name in _axes_commands: + called_name = _axes_commands[name] or name + method = getattr(Axes, called_name) + gca = __getattr__('gca') + if name != 'sci': + sci = __getattr__('sci') + + if name in {'contour', 'contourf', 'tricontour', 'tricontourf'}: + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + __ret = getattr(gca(), called_name)(*args, **kwargs) + if __ret._A is not None: + sci(__ret) + return __ret + + elif name in {'hexbin', 'imshow', 'pcolor', 'pcolormesh', 'quiver', 'scatter', + 'tripcolor'}: + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + __ret = getattr(gca(), called_name)(*args, **kwargs) + sci(__ret) + return __ret + + elif name in {'hist2d', 'specgram'}: + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + __ret = getattr(gca(), called_name)(*args, **kwargs) + sci(__ret[-1]) + return __ret + + elif name == 'spy': + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + __ret = getattr(gca(), called_name)(*args, **kwargs) + if isinstance(__ret, cm.ScalarMappable): + sci(__ret) + return __ret + + elif name == 'streamplot': + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + __ret = getattr(gca(), called_name)(*args, **kwargs) + sci(__ret.lines) + return __ret -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def viridis(): - """ - Set the colormap to 'viridis'. + else: + @_make_pyplot_wrapper(method, name) + def _pyplot_wrapper(*args, **kwargs): + return getattr(gca(), called_name)(*args, **kwargs) - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('viridis') + return _pyplot_wrapper + elif name in _cmaps: + def _pyplot_wrapper(): + """ + Set the colormap to {name!r}. -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def nipy_spectral(): - """ - Set the colormap to 'nipy_spectral'. + This changes the default colormap as well as the colormap of the current + image if there is one. See ``help(colormaps)`` for more information. + """ + set_cmap(name) - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap('nipy_spectral') + if _pyplot_wrapper is not None: + _pyplot_wrapper.__doc__ = _pyplot_wrapper.__doc__.format(name=name) + _pyplot_wrapper.__name__ = _pyplot_wrapper.__qualname__ = name + _pyplot_wrapper.__module__ = 'matplotlib.pyplot' + return _pyplot_wrapper -__all__ += [ - 'acorr', 'angle_spectrum', 'annotate', 'arrow', 'autoscale', - 'axhline', 'axhspan', 'axis', 'axline', 'axvline', 'axvspan', 'bar', - 'barbs', 'barh', 'bar_label', 'boxplot', 'broken_barh', 'clabel', - 'cohere', 'contour', 'contourf', 'csd', 'errorbar', 'eventplot', - 'fill', 'fill_between', 'fill_betweenx', 'grid', 'hexbin', 'hist', - 'stairs', 'hist2d', 'hlines', 'imshow', 'legend', 'locator_params', - 'loglog', 'magnitude_spectrum', 'margins', 'minorticks_off', - 'minorticks_on', 'pcolor', 'pcolormesh', 'phase_spectrum', 'pie', - 'plot', 'plot_date', 'psd', 'quiver', 'quiverkey', 'scatter', - 'semilogx', 'semilogy', 'specgram', 'spy', 'stackplot', 'stem', - 'step', 'streamplot', 'table', 'text', 'tick_params', - 'ticklabel_format', 'tricontour', 'tricontourf', 'tripcolor', - 'triplot', 'violinplot', 'vlines', 'xcorr', 'sci', 'title', 'xlabel', - 'ylabel', 'xscale', 'yscale', 'figimage', 'figtext', 'gca', 'gci', - 'ginput', 'subplots_adjust', 'suptitle', 'tight_layout', - 'waitforbuttonpress', 'contour', 'contourf', 'hexbin', 'scatter', - 'pcolor', 'pcolormesh', 'hist2d', 'imshow', 'spy', 'quiver', - 'specgram', 'streamplot', 'tricontour', 'tricontourf', 'tripcolor', - 'autumn', 'bone', 'cool', 'copper', 'flag', 'gray', 'hot', 'hsv', - 'jet', 'pink', 'prism', 'spring', 'summer', 'winter', 'magma', - 'inferno', 'plasma', 'viridis', 'nipy_spectral' -] + raise AttributeError(f"module 'matplotlib.pyplot' has no attribute {name!r}") diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index 292f81f1292e..10b3f1369cb6 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -1,46 +1,13 @@ -import difflib - import numpy as np -import sys from pathlib import Path import pytest import matplotlib as mpl -from matplotlib.testing import subprocess_run_for_testing from matplotlib import pyplot as plt from matplotlib._api import MatplotlibDeprecationWarning -def test_pyplot_up_to_date(tmpdir): - gen_script = Path(mpl.__file__).parents[2] / "tools/boilerplate.py" - if not gen_script.exists(): - pytest.skip("boilerplate.py not found") - orig_contents = Path(plt.__file__).read_text() - plt_file = tmpdir.join('pyplot.py') - plt_file.write_text(orig_contents, 'utf-8') - - subprocess_run_for_testing( - [sys.executable, str(gen_script), str(plt_file)], - check=True) - new_contents = plt_file.read_text('utf-8') - - if orig_contents != new_contents: - diff_msg = '\n'.join( - difflib.unified_diff( - orig_contents.split('\n'), new_contents.split('\n'), - fromfile='found pyplot.py', - tofile='expected pyplot.py', - n=0, lineterm='')) - pytest.fail( - "pyplot.py is not up-to-date. Please run " - "'python tools/boilerplate.py' to update pyplot.py. " - "This needs to be done from an environment where your " - "current working copy is installed (e.g. 'pip install -e'd). " - "Here is a diff of unexpected differences:\n%s" % diff_msg - ) - - def test_copy_docstring_and_deprecators(recwarn): @mpl._api.rename_parameter("(version)", "old", "new") @mpl._api.make_keyword_only("(version)", "kwo") diff --git a/tools/boilerplate.py b/tools/boilerplate.py deleted file mode 100644 index 697eea9ad9e2..000000000000 --- a/tools/boilerplate.py +++ /dev/null @@ -1,405 +0,0 @@ -""" -Script to autogenerate pyplot wrappers. - -When this script is run, the current contents of pyplot are -split into generatable and non-generatable content (via the magic header -:attr:`PYPLOT_MAGIC_HEADER`) and the generatable content is overwritten. -Hence, the non-generatable content should be edited in the pyplot.py file -itself, whereas the generatable content must be edited via templates in -this file. -""" - -# Although it is possible to dynamically generate the pyplot functions at -# runtime with the proper signatures, a static pyplot.py is simpler for static -# analysis tools to parse. - -from enum import Enum -import inspect -from inspect import Parameter -import itertools -from pathlib import Path -import sys -import textwrap - -# This line imports the installed copy of matplotlib, and not the local copy. -import numpy as np -from matplotlib import _api, mlab -from matplotlib.axes import Axes -from matplotlib.backend_bases import MouseButton -from matplotlib.figure import Figure - - -# we need to define a custom str because py310 change -# In Python 3.10 the repr and str representation of Enums changed from -# -# str: 'ClassName.NAME' -> 'NAME' -# repr: '' -> 'ClassName.NAME' -# -# which is more consistent with what str/repr should do, however this breaks -# boilerplate which needs to get the ClassName.NAME version in all versions of -# Python. Thus, we locally monkey patch our preferred str representation in -# here. -# -# bpo-40066 -# https://github.com/python/cpython/pull/22392/ -def enum_str_back_compat_patch(self): - return f'{type(self).__name__}.{self.name}' - -# only monkey patch if we have to. -if str(MouseButton.LEFT) != 'MouseButton.Left': - MouseButton.__str__ = enum_str_back_compat_patch - - -# This is the magic line that must exist in pyplot, after which the boilerplate -# content will be appended. -PYPLOT_MAGIC_HEADER = ( - "################# REMAINING CONTENT GENERATED BY boilerplate.py " - "##############\n") - -AUTOGEN_MSG = """ - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost.""" - -AXES_CMAPPABLE_METHOD_TEMPLATE = AUTOGEN_MSG + """ -@_copy_docstring_and_deprecators(Axes.{called_name}) -def {name}{signature}: - __ret = gca().{called_name}{call} - {sci_command} - return __ret -""" - -AXES_METHOD_TEMPLATE = AUTOGEN_MSG + """ -@_copy_docstring_and_deprecators(Axes.{called_name}) -def {name}{signature}: - return gca().{called_name}{call} -""" - -FIGURE_METHOD_TEMPLATE = AUTOGEN_MSG + """ -@_copy_docstring_and_deprecators(Figure.{called_name}) -def {name}{signature}: - return gcf().{called_name}{call} -""" - -CMAP_TEMPLATE = ''' -def {name}(): - """ - Set the colormap to {name!r}. - - This changes the default colormap as well as the colormap of the current - image if there is one. See ``help(colormaps)`` for more information. - """ - set_cmap({name!r}) -''' # Colormap functions. - - -class value_formatter: - """ - Format function default values as needed for inspect.formatargspec. - The interesting part is a hard-coded list of functions used - as defaults in pyplot methods. - """ - - def __init__(self, value): - if value is mlab.detrend_none: - self._repr = "mlab.detrend_none" - elif value is mlab.window_hanning: - self._repr = "mlab.window_hanning" - elif value is np.mean: - self._repr = "np.mean" - elif value is _api.deprecation._deprecated_parameter: - self._repr = "_api.deprecation._deprecated_parameter" - elif isinstance(value, Enum): - # Enum str is Class.Name whereas their repr is . - self._repr = str(value) - else: - self._repr = repr(value) - - def __repr__(self): - return self._repr - - -def generate_function(name, called_fullname, template, **kwargs): - """ - Create a wrapper function *pyplot_name* calling *call_name*. - - Parameters - ---------- - name : str - The function to be created. - called_fullname : str - The method to be wrapped in the format ``"Class.method"``. - template : str - The template to be used. The template must contain {}-style format - placeholders. The following placeholders are filled in: - - - name: The function name. - - signature: The function signature (including parentheses). - - called_name: The name of the called function. - - call: Parameters passed to *called_name* (including parentheses). - - **kwargs - Additional parameters are passed to ``template.format()``. - """ - text_wrapper = textwrap.TextWrapper( - break_long_words=False, width=70, - initial_indent=' ' * 8, subsequent_indent=' ' * 8) - - # Get signature of wrapped function. - class_name, called_name = called_fullname.split('.') - class_ = {'Axes': Axes, 'Figure': Figure}[class_name] - - meth = getattr(class_, called_name) - decorator = _api.deprecation.DECORATORS.get(meth) - # Generate the wrapper with the non-kwonly signature, as it will get - # redecorated with make_keyword_only by _copy_docstring_and_deprecators. - if decorator and decorator.func is _api.make_keyword_only: - meth = meth.__wrapped__ - signature = inspect.signature(meth) - # Replace self argument. - params = list(signature.parameters.values())[1:] - signature = str(signature.replace(parameters=[ - param.replace(default=value_formatter(param.default)) - if param.default is not param.empty else param - for param in params])) - if len('def ' + name + signature) >= 80: - # Move opening parenthesis before newline. - signature = '(\n' + text_wrapper.fill(signature).replace('(', '', 1) - # How to call the wrapped function. - call = '(' + ', '.join(( - # Pass "intended-as-positional" parameters positionally to avoid - # forcing third-party subclasses to reproduce the parameter names. - '{0}' - if param.kind in [ - Parameter.POSITIONAL_OR_KEYWORD] - and param.default is Parameter.empty else - # Only pass the data kwarg if it is actually set, to avoid forcing - # third-party subclasses to support it. - '**({{"data": data}} if data is not None else {{}})' - # Avoid linebreaks in the middle of the expression, by using \0 as a - # placeholder that will be substituted after wrapping. - .replace(' ', '\0') - if param.name == "data" else - '{0}={0}' - if param.kind in [ - Parameter.POSITIONAL_OR_KEYWORD, - Parameter.KEYWORD_ONLY] else - '{0}' - if param.kind is Parameter.POSITIONAL_ONLY else - '*{0}' - if param.kind is Parameter.VAR_POSITIONAL else - '**{0}' - if param.kind is Parameter.VAR_KEYWORD else - None).format(param.name) - for param in params) + ')' - MAX_CALL_PREFIX = 18 # len(' __ret = gca().') - if MAX_CALL_PREFIX + max(len(name), len(called_name)) + len(call) >= 80: - call = '(\n' + text_wrapper.fill(call[1:]).replace('\0', ' ') - # Bail out in case of name collision. - for reserved in ('gca', 'gci', 'gcf', '__ret'): - if reserved in params: - raise ValueError( - f'Method {called_fullname} has kwarg named {reserved}') - - return template.format( - name=name, - called_name=called_name, - signature=signature, - call=call, - **kwargs) - - -def boilerplate_gen(): - """Generator of lines for the automated part of pyplot.""" - - _figure_commands = ( - 'figimage', - 'figtext:text', - 'gca', - 'gci:_gci', - 'ginput', - 'subplots_adjust', - 'suptitle', - 'tight_layout', - 'waitforbuttonpress', - ) - - # These methods are all simple wrappers of Axes methods by the same name. - _axes_commands = ( - 'acorr', - 'angle_spectrum', - 'annotate', - 'arrow', - 'autoscale', - 'axhline', - 'axhspan', - 'axis', - 'axline', - 'axvline', - 'axvspan', - 'bar', - 'barbs', - 'barh', - 'bar_label', - 'boxplot', - 'broken_barh', - 'clabel', - 'cohere', - 'contour', - 'contourf', - 'csd', - 'errorbar', - 'eventplot', - 'fill', - 'fill_between', - 'fill_betweenx', - 'grid', - 'hexbin', - 'hist', - 'stairs', - 'hist2d', - 'hlines', - 'imshow', - 'legend', - 'locator_params', - 'loglog', - 'magnitude_spectrum', - 'margins', - 'minorticks_off', - 'minorticks_on', - 'pcolor', - 'pcolormesh', - 'phase_spectrum', - 'pie', - 'plot', - 'plot_date', - 'psd', - 'quiver', - 'quiverkey', - 'scatter', - 'semilogx', - 'semilogy', - 'specgram', - 'spy', - 'stackplot', - 'stem', - 'step', - 'streamplot', - 'table', - 'text', - 'tick_params', - 'ticklabel_format', - 'tricontour', - 'tricontourf', - 'tripcolor', - 'triplot', - 'violinplot', - 'vlines', - 'xcorr', - # pyplot name : real name - 'sci:_sci', - 'title:set_title', - 'xlabel:set_xlabel', - 'ylabel:set_ylabel', - 'xscale:set_xscale', - 'yscale:set_yscale', - ) - - cmappable = { - 'contour': 'if __ret._A is not None: sci(__ret) # noqa', - 'contourf': 'if __ret._A is not None: sci(__ret) # noqa', - 'hexbin': 'sci(__ret)', - 'scatter': 'sci(__ret)', - 'pcolor': 'sci(__ret)', - 'pcolormesh': 'sci(__ret)', - 'hist2d': 'sci(__ret[-1])', - 'imshow': 'sci(__ret)', - 'spy': 'if isinstance(__ret, cm.ScalarMappable): sci(__ret) # noqa', - 'quiver': 'sci(__ret)', - 'specgram': 'sci(__ret[-1])', - 'streamplot': 'sci(__ret.lines)', - 'tricontour': 'if __ret._A is not None: sci(__ret) # noqa', - 'tricontourf': 'if __ret._A is not None: sci(__ret) # noqa', - 'tripcolor': 'sci(__ret)', - } - - for spec in _figure_commands: - if ':' in spec: - name, called_name = spec.split(':') - else: - name = called_name = spec - yield generate_function(name, f'Figure.{called_name}', - FIGURE_METHOD_TEMPLATE) - - for spec in _axes_commands: - if ':' in spec: - name, called_name = spec.split(':') - else: - name = called_name = spec - - template = (AXES_CMAPPABLE_METHOD_TEMPLATE if name in cmappable else - AXES_METHOD_TEMPLATE) - yield generate_function(name, f'Axes.{called_name}', template, - sci_command=cmappable.get(name)) - - cmaps = ( - 'autumn', - 'bone', - 'cool', - 'copper', - 'flag', - 'gray', - 'hot', - 'hsv', - 'jet', - 'pink', - 'prism', - 'spring', - 'summer', - 'winter', - 'magma', - 'inferno', - 'plasma', - 'viridis', - "nipy_spectral" - ) - # add all the colormaps (autumn, hsv, ....) - for name in cmaps: - yield AUTOGEN_MSG - yield CMAP_TEMPLATE.format(name=name) - - # extend __all__ - all_text_wrapper = textwrap.TextWrapper( - break_long_words=False, width=74, - initial_indent=' ' * 4, subsequent_indent=' ' * 4) - - t = all_text_wrapper.fill( - ', '.join([ - "'%s'" % funcname.split(':', 1)[0] - for funcname in itertools.chain( - _axes_commands, _figure_commands, cmappable, cmaps - )])) - - yield '\n' - yield '__all__ += [\n{}\n]\n'.format(t) - - -def build_pyplot(pyplot_path): - pyplot_orig = pyplot_path.read_text().splitlines(keepends=True) - try: - pyplot_orig = pyplot_orig[:pyplot_orig.index(PYPLOT_MAGIC_HEADER) + 1] - except IndexError as err: - raise ValueError('The pyplot.py file *must* have the exact line: %s' - % PYPLOT_MAGIC_HEADER) from err - - with pyplot_path.open('w') as pyplot: - pyplot.writelines(pyplot_orig) - pyplot.writelines(boilerplate_gen()) - - -if __name__ == '__main__': - # Write the matplotlib.pyplot file. - if len(sys.argv) > 1: - pyplot_path = Path(sys.argv[1]) - else: - pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py" - build_pyplot(pyplot_path)