From: Paul H. <pmh...@gm...> - 2015-03-08 00:28:49
|
IMO, this seems like a bug. I would expect bars to change height with zoom/limit levels. -p — Sent from Mailbox On Sat, Mar 7, 2015 at 4:20 PM, Tomo Lazovich <laz...@gm...> wrote: > Hello matplotlib developers, > I'm not sure if this is the right mailing list for this question, so please > re-direct me if it is not. > I am wondering whether it is possible to have a histogram in pyplot > normalized to the total length of the list input, rather than just the bins > showing on the plot (i.e. include those entries in the "overflow" and > "underflow", off the right and left edges of the plot). As far as I can > tell, the normed option of pyplot.hist currently makes it so that the area > under the bins showing is 1. This can lead to a situation like the one > pasted below, where when I look at the whole histogram the bins have > certain values but when I try to zoom in to see one part of the plot better > those values change. > I can think of two ways to solve this as of now: > 1) Use the weights option to scale each entry by 1/len(input) rather than > using normed=True. > 2) Somehow add the contents of the overflow to the last bin of the plot, > which would keep the normalizations constant for earlier bins even if you > extend the axes. > Is there a better way of doing this? If the option does not currently > exist, I am also happy to help implement it if the community would find it > desirable. > Thanks for your help! > Tomo Lazovich > P.S. Here is a toy example of what I mean: >>> import numpy as np >>> import matplotlib.pyplot as plt >>> h1 = [0, 0, 0, 1, 1, 2, 3] >>> my_bins = np.linspace(-0.5, 4.5, 6) >>> plt.hist(h1, bins=my_bins, normed=True) >>> plt.show() > gives > [image: Inline image 1] > Now, if I change the range on the x axis that I would like plot: >>> my_bins2 = np.linspace(-0.5, 1.5, 3) >>> plt.hist(h1, bins=my_bins2, normed=True) >>> plt.show() > [image: Inline image 2] > The y values have changed to 0.6 and 0.4 because the normalization does not > include the values that are cut off to the right of the plot. |