Thanks to visit codestin.com
Credit goes to github.com

Skip to content

empty imshow crashes python #7886

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

Closed
tacaswell opened this issue Jan 20, 2017 · 8 comments
Closed

empty imshow crashes python #7886

tacaswell opened this issue Jan 20, 2017 · 8 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@tacaswell
Copy link
Member

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

Bug summary

  • A short 1-2 sentences that succinctly describes the bug

An empty array in imshow + an extent crashes

Code for reproduction

  • A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required
import matplotlib.pyplot as plt
plt.ioff()
fig, ax = plt.subplots()
im = ax.imshow([[]])
im.set_extent([-5, 5, -5, 5])
fig.canvas.draw()

Actual outcome

  • The output produced by the above code, which may be a screenshot, console output, etc.
22:51 $ python /tmp/st.py 
/home/tcaswell/src/p/matplotlib/lib/matplotlib/axes/_base.py:2903: UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=-0.5, right=-0.5
  'left=%s, right=%s') % (left, right))
/home/tcaswell/src/p/matplotlib/lib/matplotlib/image.py:327: RuntimeWarning: divide by zero encountered in double_scalars
  in_bbox.width / A.shape[1],
Floating point exception (core dumped)

Expected outcome

  • A description of the expected outcome from the code snippet
    not crash

  • If this used to work in an earlier version of Matplotlib, please note the version it used to work on
    1.5.3 (reportedly, not verified)

  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    py3.6, pyqt4, linux.

  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    source 😈

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Jan 20, 2017
@tacaswell
Copy link
Member Author

If you check the extent before setting it, it is (-0.5, -0.5, 0.5, -0.5) making both directions non-singular + having an empty image seems to be the trigger for this.

@astrofrog
Copy link
Contributor

I also get a crash if I don't set any extent and instead just use set_data

In [1]:  import numpy as np

In [2]: im = plt.imshow(np.random.random((128,128)))

In [3]: im.set_data([[]])

In [4]: /Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/matplotlib/image.py:327: RuntimeWarning: divide by zero encountered in double_scalars
  in_bbox.width / A.shape[1],
Floating point exception: 8

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 28, 2017
@tacaswell
Copy link
Member Author

if you have already set data, then the extents are implicitly set.

@astrofrog
Copy link
Contributor

Ok that makes sense

@NelleV
Copy link
Member

NelleV commented Jan 29, 2017

I have a fix, but I don't think @tacaswell is going to like it 👿
Can we just raise a proper error if someone tries to plot an empty image?

@tacaswell
Copy link
Member Author

subbing in an empty image used to work (and is something I do some-what frequently as the bug report came out of some code I maintain).

There just needs to be a short-circuit someplace, either in the c++ or just before we call the c++.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Feb 1, 2017
Do not bother trying to render Images which have zero-dimension in any
direction.  Simply return from the `draw` method early

closes matplotlib#7886
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Feb 1, 2017
Do not bother trying to render Images which have zero-dimension in any
direction.  Simply return from the `draw` method early

closes matplotlib#7886
@dstansby
Copy link
Member

Looks like this is fixed on 2.0.x

@tacaswell
Copy link
Member Author

A lot of these will auto-close when we do the 2.0.x -> master merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

No branches or pull requests

4 participants