Skip to content

Impossible to configure minor/major grid line style independently in rcParams #13919

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

Open
NGJROMO opened this issue Apr 10, 2019 · 16 comments · May be fixed by #29481
Open

Impossible to configure minor/major grid line style independently in rcParams #13919

NGJROMO opened this issue Apr 10, 2019 · 16 comments · May be fixed by #29481
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! keep Items to be ignored by the “Stale” Github Action New feature topic: rcparams

Comments

@NGJROMO
Copy link

NGJROMO commented Apr 10, 2019

Hi,

As far as I can see, the only customization to the grid that is possible right now in rcParams is:

mpl.rcParams['grid.color']  
mpl.rcParams['grid.alpha']
mpl.rcParams['grid.linewidth']
mpl.rcParams['grid.linestyle']

Is it possible to change these keys so that it is possible to configure minor and major grid line styles independently from each other?

Something like:

mpl.rcParams['grid.minor.color']  
mpl.rcParams['grid.minor.alpha']
mpl.rcParams['grid.minor.linewidth']
mpl.rcParams['grid.minor.linestyle']
mpl.rcParams['grid.major.color']  
mpl.rcParams['grid.major.alpha']
mpl.rcParams['grid.major.linewidth']
mpl.rcParams['grid.major.linestyle']
@timhoffm
Copy link
Member

There are no separate parameters for major/minor grid properties in rcParams.

You can currently only configure them programmatically.

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

x = np.arange(10)

ax = plt.gca()
ax.plot(x, x**2)
ax.xaxis.set_minor_locator(MultipleLocator(0.5))
ax.grid(which='both')
ax.tick_params(which='minor', grid_linestyle='--')

@zertrin
Copy link

zertrin commented Apr 15, 2019

I was just looking for exactly this feature. I already did it programmatically before, but as I have a large number of different plots with major and minor gridlines, this is quite inconvenient.

Looking forward such an option in rcParams!

@dgua
Copy link

dgua commented Apr 8, 2020

Yes, PLEASE. I'm with @NGJROMO.
The programmatic way shown above is too cumbersome (and, is there a way to also set line width, color, and alpha?).

This is back to one year ago. Is there any way it can be implemented soon?

Here is what I want:
ExamplePlot-Two Grids

Thanks.

@hjstein
Copy link

hjstein commented Apr 21, 2020

I'm surprised that the settings are not automatically mirrored in the style sheet & rcParams. In fact, I would have thought that all of the defaults would be set up in rcParams & that would drive everything else.

@neutrinonerd3333
Copy link

Bumping this issue -- I've found it unwieldy to copy and paste the same code snippet to get a fixed style that I almost always want, and would also appreciate support for differently styled major and minor gridlines via rc params.

@jklymak
Copy link
Member

jklymak commented Nov 23, 2021

A motivated user could always write a PR for this. https://matplotlib.org/stable/devel/contributing.html However, be aware that new rcparams face a relatively high bar for acceptance.

One can also write their own styling wrapper if they are always doing this.

import matplotlib.pyplot as plt 

my_style_subplots(*arg, **kwargs):
    fig, axs = plt.subplots(*args, **kwargs)
    for ax in axs.flat:
       ax.xaxis.set_minor_locator(MultipleLocator(0.5))
       ax.grid(which='both')
       ax.tick_params(which='minor', grid_linestyle='--')
    return fig, axs
import mystyles as myplt

fig, ax = mplt.subplots(3, 2, sharedx=True)

@dgua
Copy link

dgua commented Nov 23, 2021

Sorry but above answer isn't satisfactory IMHO. That is not what we are asking. Also, it forces ax.xaxis.set_minor_locator(MultipleLocator(0.5)), which I would not want in general.

This is a straightforward request and not hard to implement. It's from 2019 for crying out loud.

@jklymak
Copy link
Member

jklymak commented Nov 23, 2021

This is a straightforward request and not hard to implement. It's from 2019 for crying out loud.

Matplotlib is a volunteer organization and PRs are always welcome!

@DanHallatt
Copy link

DanHallatt commented Feb 5, 2022

I agree with @neutrinonerd3333, and am in the same boat as him and @zertrin.

One other thing that I think is related, is the inability to specify tick label font in rcParams. I am able to specify the overall general font as Helvetica for example, successfully changing the font of everything in my generated plots, however this does not change the font of the tick labels (they remain in a serif font..)! I thought I could specify this in the rcParams (with something like font..ticklabel.family: sans-serif, font.ticklabel.serif: Helvetica), but it turns out this is another limitation that must be done programmatically... making each of my plots even more cumbersome and repetitive to code.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 12, 2023
@timhoffm
Copy link
Member

This is a highly requested feature. -> keep

@timhoffm timhoffm added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 12, 2023
@YamenMejri
Copy link

any updates on this?

@nNeD5
Copy link

nNeD5 commented Apr 17, 2024

Still need this feature

@jklymak jklymak added Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Apr 17, 2024
Copy link

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the
Matplotlib internals. To get started, please see our contributing
guide
.

We do not assign issues. Check the Development section in the sidebar for linked pull
requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please
collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication
channels
.

@jklymak
Copy link
Member

jklymak commented Apr 17, 2024

Maybe some extra tagging will help, but someone who wants this feature needs to propose a PR for it to get implemented.

@timhoffm
Copy link
Member

As a word of warning: This is not as trivial as it sounds. We want to maintain backward-compatibility, i.e. if somebody changes th grid.* parameters, they should still affect both grids - unless of course they specify grid.minor.* explicitly. This possibly needs some hierachial lookup/dependency between the keys, which is not a concept we have in rcParams so far.

konmenel added a commit to konmenel/matplotlib that referenced this issue Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! keep Items to be ignored by the “Stale” Github Action New feature topic: rcparams
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants