matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

[Doc]: add gridlines to style sheet reference

Open story645 opened this issue 3 years ago • 0 comments

Documentation Link

https://matplotlib.org/devdocs/gallery/style_sheets/style_sheets_reference.html

Problem

The only style sheet examples that show the default grid color in that style are the styles that turn grids on by default. I think it'd be useful to show which color the grid defaults to when turned on, in part to flag color choices such as #23598

Suggested improvement

I suggest turning on the grid for the line example since my guess is that's the most common use case for grids. This is a good-ish first issue since it involves adding something like an ax.grid call to one of the plots in the example (https://github.com/matplotlib/matplotlib/blob/main/examples/style_sheets/style_sheets_reference.py) but there might be lots of back and forth on the PR on which example gets the grid.

story645 avatar Aug 10 '22 19:08 story645

Hi! If it is okay, I can work on this issue.

masaaldosey avatar Aug 19 '22 19:08 masaaldosey

Go for it! We generally don't assign issues, but first person with an open PR gets priority. https://matplotlib.org/devdocs/devel/index.html

story645 avatar Aug 19 '22 19:08 story645

The style sheet reference show what happens when you use the defaults, so turning the grid on in addition seems very misleading?

jklymak avatar Aug 20 '22 15:08 jklymak

I think if the grid line color is considered part of the 'unchangable style API' then it should be documented, and I think the current way that style is documented is via this reference. This is the default if you call the grid function, just like the other examples show, for example, the default if you call the plot or scatter functions.

I'd be all for a new style sheet reference that visually documents what each individual element in the style sheet is set, but I think that's a bigger project.

story645 avatar Aug 21 '22 01:08 story645

Hi @story645, was playing around a bit with the style sheet and noticed something interesting.

but there might be lots of back and forth on the PR on which example gets the grid.

def plot_colored_lines(ax):
    """Plot lines with colors following the style color cycle."""
    t = np.linspace(-10, 10, 100)

    def sigmoid(t, t0):
        return 1 / (1 + np.exp(-(t - t0)))

    nb_colors = len(plt.rcParams['axes.prop_cycle'])
    shifts = np.linspace(-5, 5, nb_colors)
    amplitudes = np.linspace(1, 1.5, nb_colors)
    for t0, a in zip(shifts, amplitudes):
        ax.plot(t, a * sigmoid(t, t0), '-')
    ax.set_xlim(-10, 10)
    ax.grid()
    return ax 

This enables the grid for default and classic, but disables it for all other styles for which it's currently enabled (e.g. Solarize_Light2, Seaborn) Could it be because of not passing any kwargs as the documentation here https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.grid.html#examples-using-matplotlib-axes-axes-grid says visible is set to True if kwargs are supplied.

Since the motive of this issue is to show the default colour of the grid, please have a look at my PR and let me know if it works.

Kinza-Raza avatar Aug 24 '22 19:08 Kinza-Raza

Could it be because of not passing any kwargs

Yup, if no argument is passed then the setting is toggled. I think it may be better to be explicit and set ax.grid(True)

https://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/axes/_base.py#L3176-L3177

story645 avatar Aug 24 '22 19:08 story645

Um @jklymak and @timhoffm, are either of your reservations strong enough to block merging #23730

story645 avatar Aug 25 '22 04:08 story645

The primary objective of the style sheet reference is to answer "How will my plot look like with this style". We need to show the basic appearance without any modifications applied. Whether the grid is shown is a fundametal sylistic element. - Yes you can activate the grid, but that's a modification like changeing linewidth. And should not be part of the basic illustration.

If you really want to show the grid color, we would have to make it very explicit in word and picture "If you activate the grid on this style it would look like this." I don't how to do this so that it's clear to the user but OTOH not too cluttered/confusing for people who are not interested in that detail.

I see your point that one cannot see the grid color from the style if the grid is not visible. But I'd argue (1) the grid color is reasonable and thus not important that people would choose a style or not. Most people would be satisfied with the grid color and if not, people who are caring that much about styling can simply choose another color via ax.grid(color='red') instead of only activating ax.grid(True)`. I thus strongly favour leaving everything as is.

timhoffm avatar Aug 25 '22 07:08 timhoffm

the grid color is reasonable and thus not important

#23598 exists because it's debatable whether the grid color is reasonable. I understand it's a small thing and probably not a priority, but I think that same can be said about each individual choice of the style, and that it's all of it collectively that adds up to a reason for choosing a style.

In a comment on #23730, @jklymak suggests flagging that the grid is/isn't the default (b/c as @Kinza-Raza mentions, it is the default for a bunch of the styles) via a small annotation. Or via a ..note: grid is on by default in [a, b, c, d] styles?

story645 avatar Aug 25 '22 17:08 story645

My two cents - since there's minimal documentation on this page a simple note wouldn't complicate comprehension or get lost in the way.

and that it's all of it collectively that adds up to a reason for choosing a style

I agree, gridlines on the line plots help set a clear distinction. For reference:

Screenshot 2022-08-26 at 5 26 56 AM

That being said perhaps a better note would be grid is enabled for line charts. And a better phrased sentence to highlight "grid is on by default for styles in which all charts have gridlines" .

Kinza-Raza avatar Aug 26 '22 00:08 Kinza-Raza

Since this now has a PR perhaps easier to discuss there?

I'd suggest label on each panel either a small title or a text in the axes. I don't think folks will read the preamble.

jklymak avatar Aug 26 '22 01:08 jklymak