Skip to content

DOC: Add more explanatory comments to gallery examples #11654

Closed
@story645

Description

@story645

@erinleeryan raised the concern that many of the matplotlib gallery examples have very little to no prose documentation, which can be frustrating for users unfamiliar with matplotlib conventions.
For example, in the stem plot example below it is unclear what markerline, stemlines, and baseline are relative the plot, and why plt.stem returns those three objects and what the plt.setp function is doing.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 2 * np.pi, 10)
markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
plt.setp(baseline, color='r', linewidth=2)

plt.show()

As suggested by @erinleeryan, it would be a welcome improvement to the docs to add short one line comments explaining what each line is doing, as shown in the pie chart example below:

# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
explode = (0, 0.1, 0, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')

fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()

As an aside, we probably should also remove "simple" and "basic" from the titles of examples, as the gallery image will indicate the level of complexity of the example to the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions