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
imshow image extends too far for large images #16378
When plotting a large image with imshow, the image may sometimes extend beyond it's reported extent, leading to to the border being obscured. I think this is related to #1441.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltfig, axes=plt.subplots(figsize=(6,3), ncols=2)
forax, ninzip(axes.flatten(), [100,200]):
mat=np.ones((n,n))
mat[1:-1,1:-1] =0# Turning clip off to see the issue betterim=ax.imshow(mat, interpolation='none', clip_on=False)
ax.set_title(f'{n}x{n}')
Actual outcome
Expected outcome
Images should fit within their extent.
#1441 is related to numerical instabilities when you are very zoomed in on a large image. This is more closely related to #12934
In this case I think the issues is related to the fact that we are down-sampling your image. The smallest quanta we can color in the output is 1pixel. If you have more data-pixels across your image than you have screen-pixels something has to give. If you increase the DPI I expect this effect to become less pronounced, but at some level, there is no way to get around this aliasing (which can also lead to some pixels being "wider" than others depending on how the beating between the screen pixels and the data pixels is lined up).
Ah, this is indeed alleviated by increasing the DPI, thanks! I suppose if I really want every pixel to be visible on zooming in, using pcolormesh and exporting in a vector format might be a better idea.
If you have a live figure, when you zoom in it will re-sample correctly, but if you want static output you can zoom in on you either need to use very high DPI (basically to match your screen dpi at the expected zoom level) or use a vector backend.
Off the top of my head, I think that setting the interpolation to 'none' and saving to a vector backend will not do any re-sampling, but I may be wrong about that.
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!
Activity
[-]imshow image extents too far for large images[/-][+]imshow image extends too far for large images[/+]tacaswell commentedon Jan 31, 2020
#1441 is related to numerical instabilities when you are very zoomed in on a large image. This is more closely related to #12934
In this case I think the issues is related to the fact that we are down-sampling your image. The smallest quanta we can color in the output is 1pixel. If you have more data-pixels across your image than you have screen-pixels something has to give. If you increase the DPI I expect this effect to become less pronounced, but at some level, there is no way to get around this aliasing (which can also lead to some pixels being "wider" than others depending on how the beating between the screen pixels and the data pixels is lined up).
human9 commentedon Jan 31, 2020
Ah, this is indeed alleviated by increasing the DPI, thanks! I suppose if I really want every pixel to be visible on zooming in, using
pcolormeshand exporting in a vector format might be a better idea.tacaswell commentedon Jan 31, 2020
If you have a live figure, when you zoom in it will re-sample correctly, but if you want static output you can zoom in on you either need to use very high DPI (basically to match your screen dpi at the expected zoom level) or use a vector backend.
Off the top of my head, I think that setting the interpolation to 'none' and saving to a vector backend will not do any re-sampling, but I may be wrong about that.
github-actions commentedon Jul 7, 2023
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!
jklymak commentedon Jul 7, 2023
I think we can safely close this.