Skip to content

Commit

Permalink
Add __all__ to pyplot
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed May 31, 2023
1 parent 28a0205 commit 6578035
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 2 deletions.
121 changes: 119 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,106 @@
implicit and explicit interfaces.
"""

# fmt: off

from __future__ import annotations

__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",
"draw_all",
"findobj",
"switch_backend",
"show",
"isinteractive",
"ion",
"ioff",
"pause",
"rc_context",
"gci",
"setp",
"xkcd",
"figure",
"gcf",
"fignum_exists",
"get_fignums",
"get_figlabels",
"connect",
"disconnect",
"close",
"clf",
"draw",
"savefig",
"ginput",
"waitforbuttonpress",
"figtext",
"suptitle",
"figimage",
"figlegend",
"axes",
"delaxes",
"sca",
"gca",
"subplot",
"subplot2grid",
"twinx",
"twiny",
"subplots_adjust",
"subplot_tool",
"tight_layout",
"box",
"xlim",
"ylim",
"xticks",
"yticks",
"rgrids",
"thetagrids",
"get_plot_commands",
"colormaps",
"color_sequences",
"colorbar",
"clim",
"set_cmap",
"imread",
"imsave",
"matshow",
"polar",
] # further expanded below with autogenerated functions

# fmt: off

from contextlib import ExitStack
from enum import Enum
import functools

import importlib
import inspect
import logging
Expand Down Expand Up @@ -4280,3 +4373,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"
]
19 changes: 19 additions & 0 deletions tools/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import functools
import inspect
from inspect import Parameter
import itertools
from pathlib import Path
import sys
import subprocess
import textwrap


# This line imports the installed copy of matplotlib, and not the local copy.
Expand Down Expand Up @@ -371,6 +373,23 @@ 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)

all_additions = all_text_wrapper.fill(
', '.join([
'"%s"' % funcname.split(':', 1)[0]
for funcname in itertools.chain(
_axes_commands, _figure_commands, cmappable, cmaps
)
])
)

yield '\n'
yield f'__all__ += [\n{all_additions}\n]\n'


def build_pyplot(pyplot_path):
pyplot_orig = pyplot_path.read_text().splitlines(keepends=True)
Expand Down

0 comments on commit 6578035

Please sign in to comment.