Skip to content

Add __all__ to pyplot #12743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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