-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: bar() displays gaps when plotting too many values #27816
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
Comments
There are simply too many bars here for the resolution of your plot. each bar is less than one pixel wide, so some bars are just missing being seen in any pixel. By default we produce a 640x480 100 dpi image. Even if your figure had no border, each bar would be less than half a pixel wide. You can improve things by increasing the dpi (or fig size... basically just need more pixels. However, you will still see effects of the discritization even up to quite high dpis (at 1000 dpi, obviously I didnt count to see whether or not bars are missing, though I think they are all present since each bar is 2-3 pixels, but there are still some bars that are directly adjacent and some that have a 1 pixel gap between them) One solution would be to use a vector format (e.g. svg, pdf), but that only kicks the can down the road, eventually to display it needs to be rasterized. some vector viewers may incorporate antialiasing to hide the gaps by displaying averaged pixels (we do similar things for some cases such as images, but not here), but if you are viewing something with fewer pixels allocated to it than data points, some compromises will be made. Basically the question becomes "is a bar plot actually an effective way of communicating the information?" and I'd argue that in general if you have 1000s of points, some amount of data reduction is basically necessary. That could be things like There are any other number of additional ways to reduce the data to a representable set, what makes sense for your data is very context dependent, so I cannot say. (Especially on a There is really nothing to be done here, this is a fundamental limit of rasterized plotting. Thus I'll close this. Thank you for reporting. |
When bars are significantly narrower than your pixel they can disappear. Your options are:
|
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
When plotting around 1300-1400 values with
matplotlib.pyplot.bar()
, empty gaps appear in the resulting bar plot. When saving the figure, the gaps shift to a different location. If a long enough title is added to the plot, the gaps also shift.Code for reproduction
Actual outcome
Expected outcome
Bar charts should be plotted correctly. Adding a title or saving the figure should not alter the chart.
Additional information
No response
Operating system
RHEL
Matplotlib Version
3.7.1
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.10.11
Jupyter version
6.5.4
Installation
conda
The text was updated successfully, but these errors were encountered: