Skip to content

imshow image extends too far for large images #16378

Closed as not planned
Closed as not planned

Description

@human9

Bug report

Bug summary

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

import numpy as np
import matplotlib.pyplot as plt

fig, axes = plt.subplots(figsize=(6,3), ncols=2)

for ax, n in zip(axes.flatten(), [100,200]):
    mat = np.ones((n,n))
    mat[1:-1,1:-1] = 0
    # Turning clip off to see the issue better
    im = ax.imshow(mat, interpolation='none', clip_on=False)
    ax.set_title(f'{n}x{n}')

Actual outcome

imshow_test

Expected outcome
Images should fit within their extent.

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 3.1.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.8.1
  • Jupyter version (if applicable):
  • Other libraries:

All packages installed from distribution repositories using pacman.

Activity

  1. changed the title [-]imshow image extents too far for large images[/-] [+]imshow image extends too far for large images[/+] on Jan 31, 2020
  2. tacaswell commented on Jan 31, 2020

    @tacaswell
    Member

    #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).

  3. human9 commented on Jan 31, 2020

    @human9
    Author

    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.

  4. tacaswell commented on Jan 31, 2020

    @tacaswell
    Member

    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.

  5. github-actions commented on Jul 7, 2023

    @github-actions

    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!

  6. jklymak commented on Jul 7, 2023

    @jklymak
    Member

    I think we can safely close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions