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
If you interactively pan around on this example the amount that the lines miss the edges of the pixels by jumps around. I suspect that this might be related to #3057 (more beating?) and smells like snap is related, but I don't understand that well enough
Punting this to 1.4.x as this is only visible if you zoom way in and looks like it is something subtle down at the bottom (maybe not a fast find or fix).
I'm not objecting the increase of the milestone. I agree that it might be difficult to debug this and that one would usually not see the difference, I just wanted to note that this effect may be visible at normal magnifications as well. I spotted it at relatively normal scale when noticing that the grid was off the pixels on the image (my real-life example is very similar to #2935).
What is the expected result of the example above? I'm asking because I see off-by-one error on PNG, but the PDF I get seems completely wrong.
If I change interpolation='none' to interpolation='nearest' the PDF looks similar to the PNG. The Agg backend has to resample images to display them, but the PDF backend does not, so when you make a very low-resolution image it's up to the viewer program to figure out how to display it.
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['pdf.compression'] = 0
plt.gcf().set_size_inches([1,1])
a=np.bitwise_xor.outer(np.arange(20)&2, np.arange(20)&2)
im = plt.imshow(a, interpolation='none', cmap='gray', origin='lower', extent=[-2,2,-2,2])
plt.gca().set_xticks(np.linspace(-2,2,21))
plt.gca().set_yticks(np.linspace(-2,2,21))
plt.gca().xaxis.set_ticklabels([])
plt.gca().yaxis.set_ticklabels([])
plt.grid(ls='-',lw=0.1,color='white')
plt.axis('square')
plt.savefig('pattern.png')
plt.savefig('pattern.pdf')
Here's how the checkerboard pattern image looks, as written in the PDF file:
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fe
00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff ff
fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 00
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fe
00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff ff
fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 00
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fe
00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff ff
fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 00
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fe
00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff ff
fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 00
ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00
00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fc 00 01 fe fe
00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff fe 00 00 ff ff
Note that the values are not all 00 or ff. Even with interpolation='none' there is some resampling going on, and the data written in the file is not exactly what was given to imshow.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Just to add that this issue still exists on main, and I can confirm that it can be seen without the Agg renderer (cairo & another). This supports the assumption that this is a problem in the image code, rather than the renderer.
I find it curious that you only see the misalignment in the y-axis, and not in the x.
Activity
pelson commentedon Oct 31, 2012
@rougier : You can make code blocks with three consecutive ``` (grave/backquotes). Hope you don't mind but I've edited your description to use them.
tacaswell commentedon Jun 3, 2014
If you interactively pan around on this example the amount that the lines miss the edges of the pixels by jumps around. I suspect that this might be related to #3057 (more beating?) and smells like snap is related, but I don't understand that well enough
tacaswell commentedon Jun 4, 2014
Punting this to 1.4.x as this is only visible if you zoom way in and looks like it is something subtle down at the bottom (maybe not a fast find or fix).
mojca commentedon Jun 4, 2014
I'm not objecting the increase of the milestone. I agree that it might be difficult to debug this and that one would usually not see the difference, I just wanted to note that this effect may be visible at normal magnifications as well. I spotted it at relatively normal scale when noticing that the grid was off the pixels on the image (my real-life example is very similar to #2935).
What is the expected result of the example above? I'm asking because I see off-by-one error on PNG, but the PDF I get seems completely wrong.
jkseppan commentedon Jul 8, 2015
If I change
interpolation='none'tointerpolation='nearest'the PDF looks similar to the PNG. The Agg backend has to resample images to display them, but the PDF backend does not, so when you make a very low-resolution image it's up to the viewer program to figure out how to display it.Here's another example adapted from #2935:
Here's how the checkerboard pattern image looks, as written in the PDF file:
Note that the values are not all 00 or ff. Even with
interpolation='none'there is some resampling going on, and the data written in the file is not exactly what was given to imshow.efiring commentedon May 22, 2016
The bug is still present after the image refactor.
14 remaining items
github-actions commentedon Mar 1, 2024
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
pelson commentedon Apr 1, 2024
Just to add that this issue still exists on main, and I can confirm that it can be seen without the Agg renderer (cairo & another). This supports the assumption that this is a problem in the image code, rather than the renderer.
I find it curious that you only see the misalignment in the y-axis, and not in the x.
timhoffm commentedon Apr 1, 2024
This should stay open.
QuLogic commentedon Jan 15, 2026
This should be fixed by #30184.