-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Colorbar fill not aligned with containing box #17103
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
I can't reproduce in Preview nor Adobe Acrobat (on Mac). |
@jklymak My roommate on a mac can reproduce this by zooming into the bottom of the bar in Preview. The gap renders only after a certain zoom level. |
Maybe a similar rendering artifact like #5694. |
I suspect not actually, because I can make a better example that also "overflows" the top of the bar instead of just "underflowing" the top. Sorry that it took awhile to get this: Better Example
Output Screenshot from Foxit Reader on Debian Jessie. Circles obviously made in post (in Gimp) for emphasis. |
For the above colorbar, opening the SVG shows that the "box" ends up being called
which is functionally equivalent to just
whereas the image is a...well.... This suggests the issue is actually the PNG position is being rounded to the nearest pixel, whereas the SVG path data is being kept as floats. By zooming in, it is clear that the bar is slightly to the left (139 instead of 139.17...), is slightly to wide (4 instead of 3.886...), etc. |
When I run the new example code, I can still not reproduce the issue. I do get
in the svg file. Here are the two files I obtain (zipped, for github to me upload them): |
Okay, thanks everyone for your patience here, after games of reinstalling-everything-in-a-fresh-venv , I think I've determined that this is a Jupyter-specific bug. The following produces a "correct" plot, as reported by @ImportanceOfBeingErnest:
However, opening a new jupyter notebook and executing
produces a PDF with the rounding issue. |
Ok, this does not mean that it's a bug with jupyter necessarily. After all, it's still matplotlib producing the output. But most probably there are some settings being made (e.g. if using IPykernel's inline backend) that change the numbers. It might then be possible to construct an example which shows the same problem outside of jupyter as well. |
Looks like #6827? |
Jupyter does set the DPI itself actually....maybe I'll dig into this, seems like it is probably the same issue. |
I can reproduce the problem with Chrome + Jupyter notebook. Matplotlib version 3.2.0. The SVG result: However, the white space goes away after I use a larger figure size (2*1.5->3*2.25) Maybe this is an issue due to rounding. |
Image positions are rounded to 72/dpi in SVG files. The default dpi in Matplotlib is 100 or so. For Jupyter notebook, dpi=72, so the position is rounded to integers. Increase the DPI would increase the precision of positions. |
Interesting - do the images need to be snapped like that? |
I'm fairly certain this is a duplicate of #6827 then. |
Thank you all! Manually setting |
Bug report
Bug summary
Definitely a low-priority bug, but at some figure sizes, there seems to be an issue with the colorbar not being drawn at the correct position in some backends (seems like PDF and SVG are affected, but not Agg).
The colorbar "fill" (the actual colored bit) will not line up with the box that contains it (the black marker edge that makes the rectangle that is filled by the color bar, see below). Seems like some sort of rounding issue.
I have a more "dramatic" example, but still need to distill it to a minimum working example, as it is a plot of proprietary data.
Code for reproduction
Actual outcome
SVG:

PDF:

PNG:

Expected outcome
The PNG output has the expected outcome.
Matplotlib version
print(matplotlib.get_backend())
):The text was updated successfully, but these errors were encountered: