You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug in bar plot, leading zeros in data (bar heights) are ignored. #2150
The bar plot function seems to ignore bar heights that are zero. For example, the data set called "freq1" does not contain a leading zero and the bar heights are correct. The data set "freq2" contains a leading zeros, both of which are ignored in the bar plot.
import pylab
import numpy as np
faces = np.array(range(11)) # the histogram bin faces
left_face = faces[:-1] # the left side face of the cell
bin_width = faces[1:]-faces[:-1]
freq1 = [-2,0,3,4,5,6,7,8,9,12]
freq2 = [0,0,3,4,5,6,7,8,9,12] # error with this data set
pylab.bar(left_face, freq1, width=bin_width)
pylab.show()
pylab.bar(left_face, freq2, width=bin_width)
pylab.show()
I think this is a feature, not a bug. The axes auto-adjust to only the visible elements of the plot. How do you plot a bar of height zero?
If you want, you may create the illusion the bars are there by adjusting the limits after plotting:
importpylabimportnumpyasnpfaces=np.array(range(11)) # the histogram bin facesleft_face=faces[:-1] # the left side face of the cellbin_width=faces[1:]-faces[:-1]
freq2= [0,0,3,4,5,6,7,8,9,12]
pylab.bar(left_face, freq2, width=bin_width)
pylab.xlim([faces[0],faces[-1]]) # adjust limitspylab.show()
I guess I was expecting a consistent behavior between the different plotting function and for the library not to edit the data set I have specified. For example, plot will include leading and trailing zeros.
Yes, I see what you mean about plotting a bar of zero height. It's just that for some application the zeros actually have meaning!
I guess I was expecting a consistent behavior between the different plotting function and for the library not to edit the data set I have specified. For example, plot will include leading and trailing zeros.
It's consistent in the sense that the axes only adjusts its own limits to the visible plot elements. When leading zeros are passed to plot, a line is still drawn between them. The line is visible and so the axes adjust to include it. When a leading zero is passed to bar, there is nothing to draw.
That said, I absolutely understand where your coming from. For bar, perhaps we need to rethink behaviour based on the data passed rather than the data visible.
For bar, perhaps we need to rethink behaviour based on the data passed rather than the data visible.
I think that would make sense, at least that is the behaviour I was expecting to see. I see where you're coming from though: you want the library to be as helpful as possible by clipping the range. My perspective (as a user) of the same situation was that the library was editing the data set I was trying to visualise.
I thought it would be interesting to see how other plotting frameworks handle this. I only got around to testing R, they have a function called barplot which does includes the zero height bars,
x=c(0,0,3,4,5,6,7,8,9,12)
barplot(x)
No I don't have any other feelings other than getting the main point across that, from the user, perspective it seems like the library has edited the data set.
Activity
dmcdougall commentedon Jun 23, 2013
I think this is a feature, not a bug. The axes auto-adjust to only the visible elements of the plot. How do you plot a bar of height zero?
If you want, you may create the illusion the bars are there by adjusting the limits after plotting:
danieljfarrell commentedon Jun 24, 2013
I guess I was expecting a consistent behavior between the different plotting function and for the library not to edit the data set I have specified. For example,
plotwill include leading and trailing zeros.Yes, I see what you mean about plotting a bar of zero height. It's just that for some application the zeros actually have meaning!
dmcdougall commentedon Jun 24, 2013
It's consistent in the sense that the axes only adjusts its own limits to the visible plot elements. When leading zeros are passed to
plot, a line is still drawn between them. The line is visible and so the axes adjust to include it. When a leading zero is passed tobar, there is nothing to draw.That said, I absolutely understand where your coming from. For
bar, perhaps we need to rethink behaviour based on the data passed rather than the data visible.Do any others have feelings about this?
danieljfarrell commentedon Jun 24, 2013
I think that would make sense, at least that is the behaviour I was expecting to see. I see where you're coming from though: you want the library to be as helpful as possible by clipping the range. My perspective (as a user) of the same situation was that the library was editing the data set I was trying to visualise.
I thought it would be interesting to see how other plotting frameworks handle this. I only got around to testing R, they have a function called
barplotwhich does includes the zero height bars,No I don't have any other feelings other than getting the main point across that, from the user, perspective it seems like the library has edited the data set.
tacaswell commentedon Jun 24, 2013
The auto-locators also do not always do what people expect on the high end (see http://stackoverflow.com/questions/17245966/matplotlib-plot-histogram-has-extra-space) by padding the axes to get to the nearest 'nice' value.
matplotlib#2150 work in progress. Patch limits get updated even if wi…
matplotlib#2150 wip - added change log
matplotlib#2150 updating comments