MEP12: Improve Gallery and Examples#
#1623, #1924, #2181
PR #2474 demonstrates a single example being cleaned up and moved to the appropriate section.
Reorganizing the matplotlib plot gallery would greatly simplify navigation of the gallery. In addition, examples should be cleaned-up and simplified for clarity.
The matplotlib gallery was recently set up to split examples up into
sections. As discussed in that PR , the current example sections
pylab_examples) aren't terribly useful to users: New
sections in the gallery would help users find relevant examples.
These sections would also guide a cleanup of the examples: Initially, all the current examples would remain and be listed under their current directories. Over time, these examples could be cleaned up and moved into one of the new sections.
This process allows users to easily identify examples that need to be
cleaned up; i.e. anything in the
Create new gallery sections. [Done]
Clean up examples and move them to the new gallery sections (over the course of many PRs and with the help of many users/developers). [In progress]
The naming of sections is critical and will guide the clean-up effort. The current sections are:
Lines, bars, and markers (more-or-less 1D data)
Shapes and collections
Images, contours, and fields
Pie and polar charts: Round things
Text, labels, and annotations
Ticks and spines
Subplots, axes, and figures
Specialty plots (e.g., sankey, radar, tornado)
Showcase (plots with tweaks to make them publication-quality)
separate sections for toolboxes (already exists: 'mplot3d', 'axes_grid', 'units', 'widgets')
These names are certainly up for debate. As these sections grow, we should reevaluate them and split them up as necessary.
The current examples in the
pylab_examples sections of
the gallery would remain in those directories until they are cleaned
up. After clean-up, they would be moved to one of the new gallery
sections described above. "Clean-up" should involve:
sphinx-gallery docstrings: a title and a description of the example formatted as follows, at the top of the example:
""" =============================== Colormaps alter your perception =============================== Here I plot the function .. math:: f(x, y) = \sin(x) + \cos(y) with different colormaps. Look at how colormaps alter your perception! """
Commented-out code should be removed.
Remove shebang line, e.g.:
Use consistent imports. In particular:
import numpy as np
import matplotlib.pyplot as plt
Avoid importing specific functions from these modules (e.g.
from numpy import sin)
Each example should focus on a specific feature (excluding
showcaseexamples, which will show more "polished" plots). Tweaking unrelated to that feature should be removed. See f7b2217, e57b5fc, and 1458aa8
pylab should be demonstrated/discussed on a dedicated help
page instead of the gallery examples.
Note: When moving an existing example, you should search for
references to that example. For example, the API documentation for
pyplot.py may use these examples to generate
plots. Use your favorite search tool (e.g., grep, ack, grin, pss) to search the matplotlib
package. See 2dc9a46
Provide links (both ways) between examples and API docs for the methods/objects used. (issue #2222)
plt.subplots(note trailing "s") in preference over
Rename the example to clarify it's purpose. For example, the most basic demo of
imshow_demo.py, and one demonstrating different interpolation settings would be
Delete examples that don't show anything new.
Some examples exercise esoteric features for unit testing. These tweaks should be moved out of the gallery to an example in the
unitdirectory located in the root directory of the package.
Add plot titles to clarify intent of the example. See bd2b13c
The website for each Matplotlib version is readily accessible, so users who want to refer to old examples can still do so.