Skip to content

Don't duplicate docstrings of pyplot-level cmap setters. #17389

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

Merged
merged 1 commit into from
Jun 23, 2020
Merged
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
240 changes: 31 additions & 209 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,11 +1978,10 @@ def colormaps():

def _setup_pyplot_info_docstrings():
"""
Generate the plotting docstring.
Setup the docstring of `plotting` and of the colormap-setting functions.

These must be done after the entire module is imported, so it is
called from the end of this module, which is generated by
boilerplate.py.
These must be done after the entire module is imported, so it is called
from the end of this module, which is generated by boilerplate.py.
"""
commands = get_plot_commands()

Expand Down Expand Up @@ -2018,6 +2017,15 @@ def _setup_pyplot_info_docstrings():
]
plotting.__doc__ = '\n'.join(lines)

for cm_name in colormaps():
if cm_name in globals():
globals()[cm_name].__doc__ = f"""
Set the colormap to {cm_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.
"""


## Plotting part 1: manually generated functions and wrappers ##

Expand Down Expand Up @@ -2979,211 +2987,25 @@ def 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")
def autumn(): set_cmap('autumn')
def bone(): set_cmap('bone')
def cool(): set_cmap('cool')
def copper(): set_cmap('copper')
def flag(): set_cmap('flag')
def gray(): set_cmap('gray')
def hot(): set_cmap('hot')
def hsv(): set_cmap('hsv')
def jet(): set_cmap('jet')
def pink(): set_cmap('pink')
def prism(): set_cmap('prism')
def spring(): set_cmap('spring')
def summer(): set_cmap('summer')
def winter(): set_cmap('winter')
def magma(): set_cmap('magma')
def inferno(): set_cmap('inferno')
def plasma(): set_cmap('plasma')
def viridis(): set_cmap('viridis')
def nipy_spectral(): set_cmap('nipy_spectral')


# 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".

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")


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
def viridis():
"""
Set the colormap to "viridis".

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")


# 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("nipy_spectral")

_setup_pyplot_info_docstrings()
2 changes: 1 addition & 1 deletion requirements/testing/flake8.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Extra pip requirements for the GitHub Actions flake8 build

flake8>=3.7
flake8>=3.8
pydocstyle<4.0
flake8-docstrings
16 changes: 4 additions & 12 deletions tools/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,7 @@ def {name}{signature}:
return gcf().{called_name}{call}
"""

# Used for colormap functions
CMAP_TEMPLATE = AUTOGEN_MSG + '''
def {name}():
"""
Set the colormap to "{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("{name}")
'''
CMAP_TEMPLATE = "def {name}(): set_cmap({name!r})\n" # Colormap functions.


class value_formatter:
Expand Down Expand Up @@ -310,6 +300,8 @@ def boilerplate_gen():
yield generate_function(name, f'Axes.{called_name}', template,
sci_command=cmappable.get(name))

yield AUTOGEN_MSG
yield '\n'
cmaps = (
'autumn',
'bone',
Expand All @@ -335,7 +327,7 @@ def boilerplate_gen():
for name in cmaps:
yield CMAP_TEMPLATE.format(name=name)

yield '\n'
yield '\n\n'
yield '_setup_pyplot_info_docstrings()'


Expand Down