Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Doc]: add gridlines to style sheet reference #23601

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

Closed
story645 opened this issue Aug 10, 2022 · 12 comments
Closed

[Doc]: add gridlines to style sheet reference #23601

story645 opened this issue Aug 10, 2022 · 12 comments
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: styles
Milestone

Comments

@story645
Copy link
Member

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 story645 added Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: styles labels Aug 10, 2022
@masaaldosey
Copy link

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

@story645
Copy link
Member Author

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

@jklymak
Copy link
Member

jklymak commented Aug 20, 2022

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

@story645
Copy link
Member Author

story645 commented Aug 21, 2022

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.

@Kinza-Raza
Copy link

Kinza-Raza commented Aug 24, 2022

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.

@story645
Copy link
Member Author

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)

If *visible* is *None* and there are no *kwargs*, this toggles the
visibility of the lines.

@story645
Copy link
Member Author

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

@story645 story645 linked a pull request Aug 25, 2022 that will close this issue
1 task
@timhoffm
Copy link
Member

timhoffm commented Aug 25, 2022

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.

@story645
Copy link
Member Author

story645 commented Aug 25, 2022

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?

@Kinza-Raza
Copy link

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

@jklymak
Copy link
Member

jklymak commented Aug 26, 2022

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.

@QuLogic
Copy link
Member

QuLogic commented Oct 4, 2022

Closed by #24020, I think.

@QuLogic QuLogic closed this as completed Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: styles
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants