diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index cc49d7190a2c..9770a7dfe8e7 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2214,7 +2214,6 @@ def set_cmap(cmap): im.set_cmap(cmap) - @docstring.copy_dedent(_imread) def imread(fname, format=None): return _imread(fname, format) @@ -2417,15 +2416,6 @@ def _autogen_docstring(base): addendum = docstring.Appender(msg, '\n\n') return lambda func: addendum(docstring.copy_dedent(base)(func)) -# This function cannot be generated by boilerplate.py because it may -# return an image or a line. -@_autogen_docstring(Axes.spy) -def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', **kwargs): - ax = gca() - ret = ax.spy(Z, precision, marker, markersize, aspect, **kwargs) - if isinstance(ret, cm.ScalarMappable): - sci(ret) - return ret # just to be safe. Interactive mode can be turned on without # calling `plt.ion()` so register it again here. @@ -2434,627 +2424,535 @@ def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', **kwargs): # to determine if they should trigger a draw. install_repl_displayhook() + ################# REMAINING CONTENT GENERATED BY boilerplate.py ############## # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.acorr) -def acorr(x, data=None, **kwargs): - ax = gca() - ret = ax.acorr(x, data=data, **kwargs) - - return ret +@docstring.copy_dedent(Axes.acorr) +def acorr(x, *, data=None, **kwargs): + return gca().acorr(x=x, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.angle_spectrum) -def angle_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, - data=None, **kwargs): - ax = gca() - ret = ax.angle_spectrum(x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, - sides=sides, data=data, **kwargs) +@docstring.copy_dedent(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=x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, + data=data, **kwargs) - return ret +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.annotate) +def annotate(text, xy, *args, **kwargs): + return gca().annotate(text=text, xy=xy, *args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.arrow) +@docstring.copy_dedent(Axes.arrow) def arrow(x, y, dx, dy, **kwargs): - ax = gca() - ret = ax.arrow(x, y, dx, dy, **kwargs) + return gca().arrow(x=x, y=y, dx=dx, dy=dy, **kwargs) - return ret +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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. -@_autogen_docstring(Axes.axhline) +@docstring.copy_dedent(Axes.axhline) def axhline(y=0, xmin=0, xmax=1, **kwargs): - ax = gca() - ret = ax.axhline(y=y, xmin=xmin, xmax=xmax, **kwargs) - - return ret + return gca().axhline(y=y, xmin=xmin, xmax=xmax, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.axhspan) +@docstring.copy_dedent(Axes.axhspan) def axhspan(ymin, ymax, xmin=0, xmax=1, **kwargs): - ax = gca() - ret = ax.axhspan(ymin, ymax, xmin=xmin, xmax=xmax, **kwargs) - - return ret + return gca().axhspan(ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.axvline) +@docstring.copy_dedent(Axes.axvline) def axvline(x=0, ymin=0, ymax=1, **kwargs): - ax = gca() - ret = ax.axvline(x=x, ymin=ymin, ymax=ymax, **kwargs) - - return ret + return gca().axvline(x=x, ymin=ymin, ymax=ymax, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.axvspan) +@docstring.copy_dedent(Axes.axvspan) def axvspan(xmin, xmax, ymin=0, ymax=1, **kwargs): - ax = gca() - ret = ax.axvspan(xmin, xmax, ymin=ymin, ymax=ymax, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.bar) -def bar(*args, **kwargs): - ax = gca() - ret = ax.bar(*args, **kwargs) - - return ret + return gca().axvspan(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.barh) -def barh(*args, **kwargs): - ax = gca() - ret = ax.barh(*args, **kwargs) - - return ret +@docstring.copy_dedent(Axes.bar) +def bar(*args, data=None, **kwargs): + return gca().bar(*args, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.broken_barh) -def broken_barh(xranges, yrange, data=None, **kwargs): - ax = gca() - ret = ax.broken_barh(xranges, yrange, data=data, **kwargs) - - return ret +@docstring.copy_dedent(Axes.barbs) +def barbs(*args, data=None, **kw): + return gca().barbs(*args, data=data, **kw) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(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_xticks=True, autorange=False, zorder=None, - data=None): - ax = gca() - ret = ax.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_xticks=manage_xticks, autorange=autorange, - zorder=zorder, data=data) - - return ret +@docstring.copy_dedent(Axes.barh) +def barh(*args, **kwargs): + return gca().barh(*args, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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_xticks=True, autorange=False, + zorder=None, *, data=None): + return gca().boxplot( + x=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_xticks=manage_xticks, + autorange=autorange, zorder=zorder, data=data) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.broken_barh) +def broken_barh(xranges, yrange, *, data=None, **kwargs): + return gca().broken_barh( + xranges=xranges, yrange=yrange, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(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): - ax = gca() - ret = ax.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, - **kwargs) - - return ret +@docstring.copy_dedent(Axes.cla) +def cla(): + return gca().cla() # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.clabel) +@docstring.copy_dedent(Axes.clabel) def clabel(CS, *args, **kwargs): - ax = gca() - ret = ax.clabel(CS, *args, **kwargs) + return gca().clabel(CS=CS, *args, **kwargs) - return ret +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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=x, y=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, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.contour) -def contour(*args, **kwargs): - ax = gca() - ret = ax.contour(*args, **kwargs) - if ret._A is not None: sci(ret) - return ret +def contour(*args, data=None, **kwargs): + __ret = gca().contour(*args, data=data, **kwargs) + if __ret._A is not None: sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.contourf) -def contourf(*args, **kwargs): - ax = gca() - ret = ax.contourf(*args, **kwargs) - if ret._A is not None: sci(ret) - return ret +def contourf(*args, data=None, **kwargs): + __ret = gca().contourf(*args, data=data, **kwargs) + if __ret._A is not None: sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.csd) -def csd(x, y, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, +@docstring.copy_dedent(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): - ax = gca() - ret = ax.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, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(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): - ax = gca() - ret = ax.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, - **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.eventplot) -def eventplot(positions, orientation='horizontal', lineoffsets=1, linelengths=1, - linewidths=None, colors=None, linestyles='solid', data=None, - **kwargs): - ax = gca() - ret = ax.eventplot(positions, orientation=orientation, - lineoffsets=lineoffsets, linelengths=linelengths, - linewidths=linewidths, colors=colors, - linestyles=linestyles, data=data, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.fill) -def fill(*args, **kwargs): - ax = gca() - ret = ax.fill(*args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.fill_between) -def fill_between(x, y1, y2=0, where=None, interpolate=False, step=None, - data=None, **kwargs): - ax = gca() - ret = ax.fill_between(x, y1, y2=y2, where=where, - interpolate=interpolate, step=step, data=data, - **kwargs) - - return ret + return_line=None, *, data=None, **kwargs): + return gca().csd( + x=x, y=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, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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=x, y=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, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.eventplot) +def eventplot( + positions, orientation='horizontal', lineoffsets=1, + linelengths=1, linewidths=None, colors=None, + linestyles='solid', *, data=None, **kwargs): + return gca().eventplot( + positions=positions, orientation=orientation, + lineoffsets=lineoffsets, linelengths=linelengths, + linewidths=linewidths, colors=colors, linestyles=linestyles, + data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.fill) +def fill(*args, data=None, **kwargs): + return gca().fill(*args, data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.fill_between) +def fill_between( + x, y1, y2=0, where=None, interpolate=False, step=None, *, + data=None, **kwargs): + return gca().fill_between( + x=x, y1=y1, y2=y2, where=where, interpolate=interpolate, + step=step, data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.fill_betweenx) +def fill_betweenx( + y, x1, x2=0, where=None, step=None, interpolate=False, *, + data=None, **kwargs): + return gca().fill_betweenx( + y=y, x1=x1, x2=x2, where=where, step=step, + interpolate=interpolate, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.fill_betweenx) -def fill_betweenx(y, x1, x2=0, where=None, step=None, interpolate=False, - data=None, **kwargs): - ax = gca() - ret = ax.fill_betweenx(y, x1, x2=x2, where=where, step=step, - interpolate=interpolate, data=data, **kwargs) - - return ret +@docstring.copy_dedent(Axes.grid) +def grid(b=None, which='major', axis='both', **kwargs): + return gca().grid(b=b, which=which, axis=axis, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(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): - ax = gca() - ret = ax.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, **kwargs) - sci(ret) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.hist) -def hist(x, bins=None, range=None, density=None, weights=None, cumulative=False, - bottom=None, histtype='bar', align='mid', orientation='vertical', - rwidth=None, log=False, color=None, label=None, stacked=False, - normed=None, data=None, **kwargs): - ax = gca() - ret = ax.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, normed=normed, data=data, **kwargs) - - return ret +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=x, y=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, **kwargs) + sci(__ret) + return __ret + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.hist) +def hist( + x, bins=None, range=None, density=None, weights=None, + cumulative=False, bottom=None, histtype='bar', align='mid', + orientation='vertical', rwidth=None, log=False, color=None, + label=None, stacked=False, normed=None, *, data=None, + **kwargs): + return gca().hist( + x=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, normed=normed, + data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.hist2d) -def hist2d(x, y, bins=10, range=None, normed=False, weights=None, cmin=None, - cmax=None, data=None, **kwargs): - ax = gca() - ret = ax.hist2d(x, y, bins=bins, range=range, normed=normed, - weights=weights, cmin=cmin, cmax=cmax, data=data, - **kwargs) - sci(ret[-1]) - return ret +def hist2d( + x, y, bins=10, range=None, normed=False, weights=None, + cmin=None, cmax=None, *, data=None, **kwargs): + __ret = gca().hist2d( + x=x, y=y, bins=bins, range=range, normed=normed, + weights=weights, cmin=cmin, cmax=cmax, data=data, **kwargs) + sci(__ret[-1]) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.hlines) -def hlines(y, xmin, xmax, colors='k', linestyles='solid', label='', data=None, - **kwargs): - ax = gca() - ret = ax.hlines(y, xmin, xmax, colors=colors, linestyles=linestyles, - label=label, data=data, **kwargs) - - return ret +@docstring.copy_dedent(Axes.hlines) +def hlines( + y, xmin, xmax, colors='k', linestyles='solid', label='', *, + data=None, **kwargs): + return gca().hlines( + y=y, xmin=xmin, xmax=xmax, colors=colors, + linestyles=linestyles, label=label, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.imshow) -def imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, - vmin=None, vmax=None, origin=None, extent=None, shape=None, - filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, - data=None, **kwargs): - ax = gca() - ret = ax.imshow(X, cmap=cmap, norm=norm, aspect=aspect, - interpolation=interpolation, alpha=alpha, vmin=vmin, - vmax=vmax, origin=origin, extent=extent, shape=shape, - filternorm=filternorm, filterrad=filterrad, - imlim=imlim, resample=resample, url=url, data=data, - **kwargs) - sci(ret) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.loglog) -def loglog(*args, **kwargs): - ax = gca() - ret = ax.loglog(*args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.magnitude_spectrum) -def magnitude_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, - sides=None, scale=None, data=None, **kwargs): - ax = gca() - ret = ax.magnitude_spectrum(x, Fs=Fs, Fc=Fc, window=window, - pad_to=pad_to, sides=sides, scale=scale, - data=data, **kwargs) - - return ret +def imshow( + X, cmap=None, norm=None, aspect=None, interpolation=None, + alpha=None, vmin=None, vmax=None, origin=None, extent=None, + shape=None, filternorm=1, filterrad=4.0, imlim=None, + resample=None, url=None, *, data=None, **kwargs): + __ret = gca().imshow( + X=X, cmap=cmap, norm=norm, aspect=aspect, + interpolation=interpolation, alpha=alpha, vmin=vmin, + vmax=vmax, origin=origin, extent=extent, shape=shape, + filternorm=filternorm, filterrad=filterrad, imlim=imlim, + resample=resample, url=url, data=data, **kwargs) + sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.pcolor) -def pcolor(*args, **kwargs): - ax = gca() - ret = ax.pcolor(*args, **kwargs) - sci(ret) - return ret +@docstring.copy_dedent(Axes.legend) +def legend(*args, **kwargs): + return gca().legend(*args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.pcolormesh) -def pcolormesh(*args, **kwargs): - ax = gca() - ret = ax.pcolormesh(*args, **kwargs) - sci(ret) - return ret +@docstring.copy_dedent(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. -@_autogen_docstring(Axes.phase_spectrum) -def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, - data=None, **kwargs): - ax = gca() - ret = ax.phase_spectrum(x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, - sides=sides, data=data, **kwargs) - - return ret +@docstring.copy_dedent(Axes.loglog) +def loglog(*args, **kwargs): + return gca().loglog(*args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.pie) -def pie(x, explode=None, labels=None, colors=None, autopct=None, - pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None, - radius=None, counterclock=True, wedgeprops=None, textprops=None, - center=(0, 0), frame=False, rotatelabels=False, data=None): - ax = gca() - ret = ax.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, data=data) - - return ret +@docstring.copy_dedent(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=x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, + scale=scale, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.plot) -def plot(*args, **kwargs): - ax = gca() - ret = ax.plot(*args, **kwargs) - - return ret +@docstring.copy_dedent(Axes.margins) +def margins(*args, **kw): + return gca().margins(*args, **kw) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.plot_date) -def plot_date(x, y, fmt='o', tz=None, xdate=True, ydate=False, data=None, - **kwargs): - ax = gca() - ret = ax.plot_date(x, y, fmt=fmt, tz=tz, xdate=xdate, ydate=ydate, - data=data, **kwargs) - - return ret +@_autogen_docstring(Axes.pcolor) +def pcolor(*args, data=None, **kwargs): + __ret = gca().pcolor(*args, data=data, **kwargs) + sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.psd) -def psd(x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, +@_autogen_docstring(Axes.pcolormesh) +def pcolormesh(*args, data=None, **kwargs): + __ret = gca().pcolormesh(*args, data=data, **kwargs) + sci(__ret) + return __ret + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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=x, Fs=Fs, Fc=Fc, window=window, pad_to=pad_to, sides=sides, + data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.pie) +def pie( + x, explode=None, labels=None, colors=None, autopct=None, + pctdistance=0.6, shadow=False, labeldistance=1.1, + startangle=None, radius=None, counterclock=True, + wedgeprops=None, textprops=None, center=(0, 0), frame=False, + rotatelabels=False, *, data=None): + return gca().pie( + x=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, data=data) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.plot) +def plot(*args, data=None, **kwargs): + return gca().plot(*args, data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.plot_date) +def plot_date( + x, y, fmt='o', tz=None, xdate=True, ydate=False, *, + data=None, **kwargs): + return gca().plot_date( + x=x, y=y, fmt=fmt, tz=tz, xdate=xdate, ydate=ydate, data=data, + **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(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): - ax = gca() - ret = ax.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, **kwargs) - - return ret + return_line=None, *, data=None, **kwargs): + return gca().psd( + x=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, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.quiver) -def quiver(*args, **kw): - ax = gca() - ret = ax.quiver(*args, **kw) - sci(ret) - return ret +def quiver(*args, data=None, **kw): + __ret = gca().quiver(*args, data=data, **kw) + sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.quiverkey) -def quiverkey(*args, **kw): - ax = gca() - ret = ax.quiverkey(*args, **kw) - - return ret +@docstring.copy_dedent(Axes.quiverkey) +def quiverkey(Q, X, Y, U, label, **kw): + return gca().quiverkey(Q=Q, X=X, Y=Y, U=U, label=label, **kw) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(Axes.scatter) -def scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, - vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, - data=None, **kwargs): - ax = gca() - ret = ax.scatter(x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm, - vmin=vmin, vmax=vmax, alpha=alpha, - linewidths=linewidths, verts=verts, - edgecolors=edgecolors, data=data, **kwargs) - sci(ret) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.semilogx) +def scatter( + x, y, s=None, c=None, marker=None, cmap=None, norm=None, + vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, + edgecolors=None, *, data=None, **kwargs): + __ret = gca().scatter( + x=x, y=y, s=s, c=c, marker=marker, cmap=cmap, norm=norm, + vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths, + verts=verts, edgecolors=edgecolors, data=data, **kwargs) + sci(__ret) + return __ret + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.semilogx) def semilogx(*args, **kwargs): - ax = gca() - ret = ax.semilogx(*args, **kwargs) - - return ret + return gca().semilogx(*args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.semilogy) +@docstring.copy_dedent(Axes.semilogy) def semilogy(*args, **kwargs): - ax = gca() - ret = ax.semilogy(*args, **kwargs) - - return ret + return gca().semilogy(*args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_autogen_docstring(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): - ax = gca() - ret = ax.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, **kwargs) - sci(ret[-1]) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.stackplot) -def stackplot(x, *args, **kwargs): - ax = gca() - ret = ax.stackplot(x, *args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.stem) -def stem(*args, **kwargs): - ax = gca() - ret = ax.stem(*args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.step) -def step(x, y, *args, **kwargs): - ax = gca() - ret = ax.step(x, y, *args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(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', data=None): - ax = gca() - ret = ax.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, - data=data) - sci(ret.lines) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.tricontour) -def tricontour(*args, **kwargs): - ax = gca() - ret = ax.tricontour(*args, **kwargs) - if ret._A is not None: sci(ret) - return ret +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=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, **kwargs) + sci(__ret[-1]) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.tricontourf) -def tricontourf(*args, **kwargs): - ax = gca() - ret = ax.tricontourf(*args, **kwargs) - if ret._A is not None: sci(ret) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.tripcolor) -def tripcolor(*args, **kwargs): - ax = gca() - ret = ax.tripcolor(*args, **kwargs) - sci(ret) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.triplot) -def triplot(*args, **kwargs): - ax = gca() - ret = ax.triplot(*args, **kwargs) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.violinplot) -def violinplot(dataset, positions=None, vert=True, widths=0.5, showmeans=False, - showextrema=True, showmedians=False, points=100, bw_method=None, - data=None): - ax = gca() - ret = ax.violinplot(dataset, positions=positions, vert=vert, - widths=widths, showmeans=showmeans, - showextrema=showextrema, showmedians=showmedians, - points=points, bw_method=bw_method, data=data) - - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.vlines) -def vlines(x, ymin, ymax, colors='k', linestyles='solid', label='', data=None, - **kwargs): - ax = gca() - ret = ax.vlines(x, ymin, ymax, colors=colors, linestyles=linestyles, - label=label, data=data, **kwargs) - - return ret +@_autogen_docstring(Axes.spy) +def spy( + Z, precision=0, marker=None, markersize=None, aspect='equal', + origin='upper', **kwargs): + __ret = gca().spy( + Z=Z, precision=precision, marker=marker, + markersize=markersize, aspect=aspect, origin=origin, **kwargs) + if isinstance(ret, cm.ScalarMappable): sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.xcorr) -def xcorr(x, y, normed=True, detrend=mlab.detrend_none, usevlines=True, - maxlags=10, data=None, **kwargs): - ax = gca() - ret = ax.xcorr(x, y, normed=normed, detrend=detrend, - usevlines=usevlines, maxlags=maxlags, data=data, - **kwargs) - - return ret +@docstring.copy_dedent(Axes.stackplot) +def stackplot(x, *args, data=None, **kwargs): + return gca().stackplot(x=x, *args, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@_autogen_docstring(Axes.barbs) -def barbs(*args, **kw): - ax = gca() - ret = ax.barbs(*args, **kw) - - return ret +@docstring.copy_dedent(Axes.stem) +def stem(*args, data=None, **kwargs): + return gca().stem(*args, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.cla) -def cla(): - ret = gca().cla() - return ret +@docstring.copy_dedent(Axes.step) +def step(x, y, *args, data=None, **kwargs): + return gca().step(x=x, y=y, *args, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.grid) -def grid(b=None, which='major', axis='both', **kwargs): - ret = gca().grid(b=b, which=which, axis=axis, **kwargs) - return ret - -# Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.legend) -def legend(*args, **kwargs): - ret = gca().legend(*args, **kwargs) - return ret +@_autogen_docstring(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', *, data=None): + __ret = gca().streamplot( + x=x, y=y, u=u, v=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, data=data) + sci(__ret.lines) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @docstring.copy_dedent(Axes.table) def table(**kwargs): - ret = gca().table(**kwargs) - return ret + return gca().table(**kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @docstring.copy_dedent(Axes.text) def text(x, y, s, fontdict=None, withdash=False, **kwargs): - ret = gca().text(x, y, s, fontdict=fontdict, withdash=withdash, **kwargs) - return ret + return gca().text( + x=x, y=y, s=s, fontdict=fontdict, withdash=withdash, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.annotate) -def annotate(*args, **kwargs): - ret = gca().annotate(*args, **kwargs) - return ret +@docstring.copy_dedent(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. @docstring.copy_dedent(Axes.ticklabel_format) def ticklabel_format(**kwargs): - ret = gca().ticklabel_format(**kwargs) - return ret + return gca().ticklabel_format(**kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.locator_params) -def locator_params(axis='both', tight=None, **kwargs): - ret = gca().locator_params(axis=axis, tight=tight, **kwargs) - return ret +@_autogen_docstring(Axes.tricontour) +def tricontour(*args, **kwargs): + __ret = gca().tricontour(*args, **kwargs) + if __ret._A is not None: sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.tick_params) -def tick_params(axis='both', **kwargs): - ret = gca().tick_params(axis=axis, **kwargs) - return ret +@_autogen_docstring(Axes.tricontourf) +def tricontourf(*args, **kwargs): + __ret = gca().tricontourf(*args, **kwargs) + if __ret._A is not None: sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.margins) -def margins(*args, **kw): - ret = gca().margins(*args, **kw) - return ret +@_autogen_docstring(Axes.tripcolor) +def tripcolor(*args, **kwargs): + __ret = gca().tripcolor(*args, **kwargs) + sci(__ret) + return __ret # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -@docstring.copy_dedent(Axes.autoscale) -def autoscale(enable=True, axis='both', tight=None): - ret = gca().autoscale(enable=enable, axis=axis, tight=tight) - return ret +@docstring.copy_dedent(Axes.triplot) +def triplot(*args, **kwargs): + return gca().triplot(*args, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.violinplot) +def violinplot( + dataset, positions=None, vert=True, widths=0.5, + showmeans=False, showextrema=True, showmedians=False, + points=100, bw_method=None, *, data=None): + return gca().violinplot( + dataset=dataset, positions=positions, vert=vert, + widths=widths, showmeans=showmeans, showextrema=showextrema, + showmedians=showmedians, points=points, bw_method=bw_method, + data=data) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.vlines) +def vlines( + x, ymin, ymax, colors='k', linestyles='solid', label='', *, + data=None, **kwargs): + return gca().vlines( + x=x, ymin=ymin, ymax=ymax, colors=colors, + linestyles=linestyles, label=label, data=data, **kwargs) + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy_dedent(Axes.xcorr) +def xcorr( + x, y, normed=True, detrend=mlab.detrend_none, usevlines=True, + maxlags=10, *, data=None, **kwargs): + return gca().xcorr( + x=x, y=y, normed=normed, detrend=detrend, usevlines=usevlines, + maxlags=maxlags, data=data, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. def autumn(): diff --git a/tools/boilerplate.py b/tools/boilerplate.py index 21e66d4802e7..1c546031a8b3 100644 --- a/tools/boilerplate.py +++ b/tools/boilerplate.py @@ -7,8 +7,6 @@ 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. - -This file is python 3 only due to the use of `inspect` """ # We did try to do the wrapping the smart way, # with callable functions and new.function, but could never get the @@ -17,14 +15,15 @@ # For some later history, see # http://thread.gmane.org/gmane.comp.python.matplotlib.devel/7068 -import os import inspect +from inspect import Signature, Parameter +import os import random -import types - import textwrap # this line imports the installed copy of matplotlib, and not the local copy +import numpy as np +from matplotlib import mlab from matplotlib.axes import Axes @@ -40,22 +39,19 @@ # Autogenerated by boilerplate.py. Do not edit as changes will be lost.""" -PLOT_TEMPLATE = AUTOGEN_MSG + """ +CMAPPABLE_TEMPLATE = AUTOGEN_MSG + """ @_autogen_docstring(Axes.%(func)s) -def %(func)s(%(argspec)s): - %(ax)s = gca() - %(ret)s = %(ax)s.%(func)s(%(call)s) +def %(func)s%(sig)s: + __ret = gca().%(func)s%(call)s %(mappable)s - return %(ret)s + return __ret """ -# Used for misc functions such as cla/legend etc. -MISC_FN_TEMPLATE = AUTOGEN_MSG + """ +NON_CMAPPABLE_TEMPLATE = AUTOGEN_MSG + """ @docstring.copy_dedent(Axes.%(func)s) -def %(func)s(%(argspec)s): - %(ret)s = gca().%(func)s(%(call)s) - return %(ret)s +def %(func)s%(sig)s: + return gca().%(func)s%(call)s """ # Used for colormap functions @@ -93,22 +89,25 @@ def {name}(): def boilerplate_gen(): """Generator of lines for the automated part of pyplot.""" - # these methods are all simple wrappers of Axes methods by the same - # name. - _plotcommands = ( + # These methods are all simple wrappers of Axes methods by the same name. + _commands = ( 'acorr', 'angle_spectrum', + 'annotate', 'arrow', + 'autoscale', 'axhline', 'axhspan', 'axvline', 'axvspan', 'bar', + 'barbs', 'barh', - 'broken_barh', 'boxplot', - 'cohere', + 'broken_barh', + 'cla', 'clabel', + 'cohere', 'contour', 'contourf', 'csd', @@ -117,13 +116,17 @@ def boilerplate_gen(): 'fill', 'fill_between', 'fill_betweenx', + 'grid', 'hexbin', 'hist', 'hist2d', 'hlines', 'imshow', + 'legend', + 'locator_params', 'loglog', 'magnitude_spectrum', + 'margins', 'pcolor', 'pcolormesh', 'phase_spectrum', @@ -137,11 +140,15 @@ def boilerplate_gen(): 'semilogx', 'semilogy', 'specgram', - # 'spy', + 'spy', 'stackplot', 'stem', 'step', 'streamplot', + 'table', + 'text', + 'tick_params', + 'ticklabel_format', 'tricontour', 'tricontourf', 'tripcolor', @@ -149,143 +156,92 @@ def boilerplate_gen(): 'violinplot', 'vlines', 'xcorr', - 'barbs', - ) - - _misccommands = ( - 'cla', - 'grid', - 'legend', - 'table', - 'text', - 'annotate', - 'ticklabel_format', - 'locator_params', - 'tick_params', - 'margins', - 'autoscale', ) cmappable = { - 'contour': 'if %(ret)s._A is not None: sci(%(ret)s)', - 'contourf': 'if %(ret)s._A is not None: sci(%(ret)s)', - 'hexbin': 'sci(%(ret)s)', - 'scatter': 'sci(%(ret)s)', - 'pcolor': 'sci(%(ret)s)', - 'pcolormesh': 'sci(%(ret)s)', - 'hist2d': 'sci(%(ret)s[-1])', - 'imshow': 'sci(%(ret)s)', - #'spy' : 'sci(%(ret)s)', ### may return image or Line2D - 'quiver': 'sci(%(ret)s)', - 'specgram': 'sci(%(ret)s[-1])', - 'streamplot': 'sci(%(ret)s.lines)', - 'tricontour': 'if %(ret)s._A is not None: sci(%(ret)s)', - 'tricontourf': 'if %(ret)s._A is not None: sci(%(ret)s)', - 'tripcolor': 'sci(%(ret)s)', + 'contour': 'if __ret._A is not None: sci(__ret)', + 'contourf': 'if __ret._A is not None: sci(__ret)', + '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)', + 'quiver': 'sci(__ret)', + 'specgram': 'sci(__ret[-1])', + 'streamplot': 'sci(__ret.lines)', + 'tricontour': 'if __ret._A is not None: sci(__ret)', + 'tricontourf': 'if __ret._A is not None: sci(__ret)', + 'tripcolor': 'sci(__ret)', } - def format_value(value): + 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. """ - if isinstance(value, types.FunctionType): - if value.__name__ in ('detrend_none', 'window_hanning'): - return '=mlab.' + value.__name__ - if value.__name__ == 'mean': - return '=np.' + value.__name__ - raise ValueError(('default value %s unknown to boilerplate.' + - 'formatvalue') % value) - return '=' + repr(value) - - text_wrapper = textwrap.TextWrapper(break_long_words=False) - - for fmt, cmdlist in [(PLOT_TEMPLATE, _plotcommands), - (MISC_FN_TEMPLATE, _misccommands)]: - for func in cmdlist: - # For some commands, an additional line is needed to set the - # color map - if func in cmappable: - mappable = ' ' + cmappable[func] % locals() + + 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" else: - mappable = '' - - # Get argspec of wrapped function - base_func = getattr(Axes, func) - has_data = 'data' in inspect.signature(base_func).parameters - work_func = inspect.unwrap(base_func) - - (args, varargs, varkw, defaults, kwonlyargs, kwonlydefs, - annotations) = inspect.getfullargspec(work_func) - args.pop(0) # remove 'self' argument - defaults = tuple(defaults or ()) - - # Add a data keyword argument if needed (fmt is PLOT_TEMPLATE) and - # possible (if *args is used, we can't just add a data - # argument in front of it since it would gobble one of the - # arguments the user means to pass via *args) - # This needs to be done here so that it goes into call - if not varargs and fmt is PLOT_TEMPLATE and has_data: - args.append('data') - defaults = defaults + (None,) - - # How to call the wrapped function - call = [] - for i, arg in enumerate(args): - if len(defaults) < len(args) - i: - call.append('%s' % arg) - else: - call.append('%s=%s' % (arg, arg)) - - # remove the data keyword as it was needed above to go into the - # call but should go after `hold` in the signature. - # This is janky as all get out, but hopefully boilerplate will - # be retired soon. - if not varargs and fmt is PLOT_TEMPLATE and has_data: - args.pop() - defaults = defaults[:-1] - - if varargs is not None: - call.append('*' + varargs) - if varkw is not None: - call.append('**' + varkw) - call = ', '.join(call) - - text_wrapper.width = 80 - 19 - len(func) - join_with = '\n' + ' ' * (18 + len(func)) - call = join_with.join(text_wrapper.wrap(call)) - - if not varargs and fmt is PLOT_TEMPLATE and has_data: - args.append('data') - defaults = defaults + (None,) - - # Now we can build the argspec for defining the wrapper - argspec = inspect.formatargspec(args, varargs, varkw, defaults, - formatvalue=format_value) - argspec = argspec[1:-1] # remove parens - - text_wrapper.width = 80 - 5 - len(func) - join_with = '\n' + ' ' * (5 + len(func)) - argspec = join_with.join(text_wrapper.wrap(argspec)) - - # A gensym-like facility in case some function takes an - # argument named washold, ax, or ret - washold, ret, ax = 'washold', 'ret', 'ax' - bad = {*args, varargs, varkw} - while washold in bad or ret in bad or ax in bad: - washold = 'washold' + str(random.randrange(10 ** 12)) - ret = 'ret' + str(random.randrange(10 ** 12)) - ax = 'ax' + str(random.randrange(10 ** 12)) - - # Since we can't avoid using some function names, - # bail out if they are used as argument names - for reserved in ('gca', 'gci'): - if reserved in bad: - msg = 'Axes method %s has kwarg named %s' % (func, reserved) - raise ValueError(msg) - - yield fmt % locals() + self._repr = repr(value) + + def __repr__(self): + return self._repr + + text_wrapper = textwrap.TextWrapper( + break_long_words=False, width=70, + initial_indent=' ' * 8, subsequent_indent=' ' * 8) + + for func in _commands: + # For some commands, an additional line is needed to set the color map. + if func in cmappable: + fmt = CMAPPABLE_TEMPLATE + mappable = ' ' + cmappable[func] + else: + fmt = NON_CMAPPABLE_TEMPLATE + + # Get signature of wrapped function. + sig = inspect.signature(getattr(Axes, func)) + + # Replace self argument. + params = list(sig.parameters.values())[1:] + + sig = str(sig.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 ' + func + sig) >= 80: + # Move opening parenthesis before newline. + sig = '(\n' + text_wrapper.fill(sig).replace('(', '', 1) + + # How to call the wrapped function. + call = '(' + ', '.join( + ('{0}={0}' if param.kind in [Parameter.POSITIONAL_OR_KEYWORD, + Parameter.KEYWORD_ONLY] else + '*{0}' if param.kind is Parameter.VAR_POSITIONAL else + '**{0}' if param.kind is Parameter.VAR_KEYWORD else + # Intentionally crash for Parameter.POSITIONAL_ONLY. + None).format(param.name) + for param in params) + ')' + MAX_CALL_PREFIX = 18 # len(' __ret = gca().') + if MAX_CALL_PREFIX + len(func) + len(call) >= 80: + call = '(\n' + text_wrapper.fill(call[1:]) + + # Bail out in case of name collision. + for reserved in ('gca', 'gci', '__ret'): + if reserved in params: + raise ValueError( + 'Axes method {} has kwarg named {}'.format(func, reserved)) + + yield fmt % locals() cmaps = ( 'autumn', @@ -328,7 +284,8 @@ def build_pyplot(): try: pyplot_orig = pyplot_orig[:pyplot_orig.index(PYPLOT_MAGIC_HEADER) + 1] except IndexError: - raise ValueError('The pyplot.py file *must* have the exact line: %s' % PYPLOT_MAGIC_HEADER) + raise ValueError('The pyplot.py file *must* have the exact line: %s' + % PYPLOT_MAGIC_HEADER) pyplot = open(pyplot_path, 'w') pyplot.writelines(pyplot_orig)