Zollern
Zollern

Reputation: 335

matplotlib: how to control custom grid linestyles for all plots?

I want to define a custom grid linestyle for my plots. I know that for any plot I can use ax.grid(b=True, dashes=[6,2,1,2]) which works perfectly as expected for that axis. How can I set this linestyle for all my plots? There is no key in matplotlib.rcParams to control it with a matplotlibrc file (rcParams['grid.linestyle'] = [6, 2, 1, 2] does not work). I couldn't find any option in seaborn to control this with a custom style, either.

Is there a way to define a linestyle for all my plots without writing my own plot function (or decorator) as a wrapper?

Upvotes: 2

Views: 1758

Answers (2)

Marcelo
Marcelo

Reputation: 183

It works for me:

plt.rcParams["grid.linestyle"]="dashed"

Upvotes: 2

Fei Yuan
Fei Yuan

Reputation: 82

Did you try to use your own style sheet? I think setting style is what you need. See Customizing plots with style sheets for more details.

Upvotes: 0

Related Questions