Skip to content
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

Bar plots are misaligned by default #7498

Closed
fonnesbeck opened this issue Jun 18, 2014 · 3 comments · Fixed by #7532
Closed

Bar plots are misaligned by default #7498

fonnesbeck opened this issue Jun 18, 2014 · 3 comments · Fixed by #7532
Labels
Milestone

Comments

@fonnesbeck
Copy link

There has been a recent change in bar plot default behavior that is causing misalignment of the bars on the y-axis. I'm not sure when this change occurred, but I will estimate 3-4 months ago.

Previously, bar plots looked like this:

good bar plot

However, the same code under '0.14.0-205-gbbde837' yields the following (ignore the theme differences):

bad bar plot

So, the bars are bizarrely pushed to the right. Is matplotlib to blame for this (running 1.4.x)?

Running Python 2.7.6 (homebrew) on OS X 10.9.3.

@jorisvandenbossche
Copy link
Member

possibly related: #6691

@sinhrks
Copy link
Member

sinhrks commented Jun 19, 2014

I'll look into this. The problem seems to occur when plotting single column without stacking. Workaround is specify stacked=True.

fig, axes = plt.subplots(2, 2)
df1 = pd.DataFrame(np.random.randn(5))
df2 = pd.DataFrame(np.random.randn(5, 2))
df1.plot(kind='bar', ax=axes[0][0], title='NG', legend=False)
df1.plot(kind='bar', stacked=True, ax=axes[0][1], title='stacked=True', legend=False)
df2.plot(kind='bar', ax=axes[1][0], title='OK', legend=False)
df2.plot(kind='bar', stacked=True, ax=axes[1][1], title='stacked=True', legend=False)

figure_1

@sinhrks
Copy link
Member

sinhrks commented Jun 21, 2014

I think I could fix this... When I worked #6691, I've tried to use the same margin which is not very good (margin was asymmetric and sometimes plot was cut off, as attached in #6644). The issue is caused by this complicated logic.

The fix always takes same margin (0.25) from right/left (or top/bottom) edge of bars. If looks OK, I'll fix some tests and make a PR.

figure_1

figure_2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants