Description
When passing a bottom
parameter to plt.hist()
, the entire histogram is shifted by that amount, as a whole, instead of just the baseline, as the documentation would suggest.
See this simple example:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
x = np.random.randn(10000)
b, e = np.histogram(x)
plt.hist(e[:-1], e, weights=b)
plt.show()
This is all fine and good.
When adding the bottom=1500
parameter:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
x = np.random.randn(10000)
b, e = np.histogram(x)
plt.hist(e[:-1], e, weights=b, bottom=1500)
plt.show()
This is what I get:
The "indicated values" of the histogram have shifted up by 1500
as well, not just the baseline. By baseline, I mean the "straight horizontal" outline of the filled region.
What I was expecting instead, can also be achieved by "unshifting" the actual data as well, by subtracting the value of the bottom
parameter from it:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
x = np.random.randn(10000)
b, e = np.histogram(x)
plt.hist(e[:-1], e, weights=b-1500, bottom=1500)
plt.show()
It might be the case that this is entirely what the original intent was behind the functionality, but at the very least, the documentation is misleading in my opinion.
Also, this might apply to plt.bar()
as well.