Skip to content

Grid=True option in plot functions overrides user settings #3188

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
mangecoeur opened this issue Mar 27, 2013 · 14 comments
Closed

Grid=True option in plot functions overrides user settings #3188

mangecoeur opened this issue Mar 27, 2013 · 14 comments

Comments

@mangecoeur
Copy link
Contributor

The plotting functions on DataFrames always have grid=True. This overrides user settings in matplotlibrc.

If you have to created a desired default plot style with the rc file, you want every plot to show with this style unless otherwise specified.
Because pandas overrides this setting you have to manually set the grid option every time.

A better behaviour would be for Pandas not to override any plot styles by default.

@ghost
Copy link

ghost commented Mar 27, 2013

Marking as 0.12, though I'm not sure that will happen unless someone steps up
to overhaul the way settings are handled.
If you're comfortable working on this, a PR would be welcome.

@goyodiaz
Copy link
Contributor

I want to work on this but I did not find any tests of plotting stuff. Should we add a test_plotting module?

@jreback
Copy link
Contributor

jreback commented Oct 27, 2013

pandas/tseries/tests/test_plotting.py

@cpcloud
Copy link
Member

cpcloud commented Oct 28, 2013

Also pandas/tests/test_graphics.py for plotting not unrelated to time series.

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 9, 2014
@jseabold
Copy link
Contributor

Came here to file this same issue so +1.

@WillAyd
Copy link
Member

WillAyd commented Jul 6, 2018

While not all plotting functions have grid=True it is rather inconsistent in the code base as of v0.23 and can use some simple cleanup

@WillAyd WillAyd added the Docs label Jul 6, 2018
@jeffgeee
Copy link

jeffgeee commented Oct 5, 2020

take

@bdrum
Copy link
Contributor

bdrum commented Oct 18, 2021

Hi everyone! I would like to take this issue, but I can't reproduce it for fresh built version.
From my side the behavior is correct:

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import matplotlib as mpl

print(pd.__version__)
print("mpl.rcParams['axes.grid']", mpl.rcParams['axes.grid'])
df = pd.DataFrame(columns=["A", "B"], data=np.random.rand(100,2))
df.plot(grid=True)
print("mpl.rcParams['axes.grid']", mpl.rcParams['axes.grid'])
f = plt.figure()
_ = f.gca().plot(np.random.rand(100))

# output
1.4.0.dev0+921.gef9416c51c
mpl.rcParams['axes.grid'] False
mpl.rcParams['axes.grid'] False

df plot(grid=True)
plt_arr

As I can see it was appeared in 0.12 first time, but looks like now every thing is fine. I also have tried set rc.axes.grid as True in the file and then run the same script but with explicit grid=False argument and without it. Works correct: when grid=False it doesn't show grid despite of the rc params and in case of grid doesn't specified it has the same behavior as in file specified i.e. grid will be shown.

@bdrum
Copy link
Contributor

bdrum commented Oct 18, 2021

take

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Oct 18, 2021

@bdrum If I understand correctly, the issue is that if you have a matplotlibrc file (https://matplotlib.org/stable/tutorials/introductory/customizing.html ), and that file specifies axes.grid=False, then you still get the grid, and it is suggested here that pandas should not override what is specified in the file. Your test above doesn't check that.

@bdrum
Copy link
Contributor

bdrum commented Oct 18, 2021

@Dr-Irv thanks for clarification.
Yes, as it shown you will get the grid in case of explicit setting of grid parameter, but in case of you miss it, the behavior will synced with rc settings:

import numpy as np
import pandas as pd
import matplotlib as mpl
print(pd.__version__)
print("mpl.rcParams['axes.grid']", mpl.rcParams['axes.grid'])
df = pd.DataFrame(columns=["A", "B"], data=np.random.rand(100,2))
df.plot()

# output 
1.4.0.dev0+921.gef9416c51c
mpl.rcParams['axes.grid'] True

df plot()

and revert back to grid false in rc file:

import numpy as np
import pandas as pd
import matplotlib as mpl
print(pd.__version__)
print("mpl.rcParams['axes.grid']", mpl.rcParams['axes.grid'])
df = pd.DataFrame(columns=["A", "B"], data=np.random.rand(100,2))
df.plot()
# output 
1.4.0.dev0+921.gef9416c51c
mpl.rcParams['axes.grid'] False

df plot(f)

According to discussion above, I can try to add some checks in tests

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Oct 18, 2021

According to discussion above, I can try to add some checks in tests

If you can create a test that verifies this in a PR, that would be great.

@bdrum
Copy link
Contributor

bdrum commented Oct 24, 2021

@Dr-Irv
As I can see this issue is a duplicate of #9792. The last one was closed and tested here.

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Oct 25, 2021

@bdrum Thanks. I will close this as a result of your discovery.

@Dr-Irv Dr-Irv closed this as completed Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants