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

shifted(?) bin positions when plotting multiple histograms at the same time #5212

Closed
anntzer opened this issue Oct 8, 2015 · 3 comments
Closed

Comments

@anntzer
Copy link
Contributor

anntzer commented Oct 8, 2015

Consider

import numpy as np
from matplotlib import pyplot as plt

mu, sigma = 1500, 100
x = mu + sigma * np.random.randn(1000, 3)

_, (ax1, ax2) = plt.subplots(2)
ax1.hist(x[:, 0], 30, range=(0, 3000), width=100)
ax1.hist(x[:, 1], 30, range=(0, 3000), width=100)
ax1.hist(x[:, 2], 30, range=(0, 3000), width=100)
ax2.hist(x, 30, range=(0, 3000), width=100)
plt.show()

hist

@tacaswell
Copy link
Member

This is nominally a feature, if you make the bars narrower they will line up in groups of 3 per bin.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 8, 2015

Perhaps some sort of warning when width is explicitly set then? (It seems more appropriate to use rwidth in that case).

@tacaswell
Copy link
Member

It looks like width is only doing something because it is falling through to the update call at the bottom of hist ( width is not explicitly documented and not really implicitly documented either as the kwargs point to patch properties and width is a Rectangle property).

If you don't pass width, it 'does the right thing':

import numpy as np
from matplotlib import pyplot as plt

mu, sigma = 1500, 100
x = mu + sigma * np.random.randn(1000, 3)

_, (ax1, ax2) = plt.subplots(2)
ax1.hist(x[:, 0], 30, range=(0, 3000))
ax1.hist(x[:, 1], 30, range=(0, 3000))
ax1.hist(x[:, 2], 30, range=(0, 3000))
ax2.hist(x, 30, range=(0, 3000))
plt.show()

so

Explicitly passing width in over-determines several things (like if you change bins or range, you can now pass in a width which is wrong).

@tacaswell tacaswell added this to the unassigned milestone Oct 12, 2015
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

2 participants