Skip to content

Make bar plot on secondary axis, the line plot on the primary axis wont show. #4387

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
tesla1060 opened this issue Jul 28, 2013 · 2 comments
Labels

Comments

@tesla1060
Copy link

Following issue #3598,

df = pd.DataFrame(np.random.uniform(size=10).reshape(5,2),columns=['A','B'])
df['A'] = df['A'] * 100
df.A.plot()
df.B.plot(kind='bar',secondary_y=True)
plt.show()

This gives the right plot, with A plotted as line in the primary axis, and B is plotted as bar in the secondary axis.

But if I index the dataframe by datetime

df = pd.DataFrame(np.random.uniform(size=10).reshape(5,2),columns=['A','B'])
df = df.set_index(pd.date_range('20130101',periods=5))
df['A'] = df['A'] * 100
df.A.plot()
df.B.plot(kind='bar',secondary_y=True)
plt.show()

This wont plot A as line in the primary axis, only the B as bar in the secondary axis. Not sure why.

@tesla1060
Copy link
Author

Update:
It seems because they are share x axis.
The below wont work if sharex=True is not removed.

 f, axarr = plt.subplots(2, sharex=True)
df.A.plot(legend=True, style='r', ax=axarr[0])
df.B.plot(ax=axarr[1], kind='bar', legend=True)
plt.show()

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 28, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@datapythonista datapythonista modified the milestones: Contributions Welcome, Someday Jul 8, 2018
@mroeschke mroeschke added the Bug label Apr 11, 2021
@pablodz
Copy link

pablodz commented May 10, 2021

#41233

@mroeschke mroeschke removed this from the Someday milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants