Skip to content

Creating a figure of size (0, 0) raises an error #16687

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
katherinekolman opened this issue Mar 5, 2020 · 4 comments
Closed

Creating a figure of size (0, 0) raises an error #16687

katherinekolman opened this issue Mar 5, 2020 · 4 comments
Milestone

Comments

@katherinekolman
Copy link

Bug report

In Matplotlib 3.2.0, creating a figure of size (0, 0) raises an error.

Code for reproduction

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(0,0))

Actual outcome

Traceback (most recent call last):
  File "test_mpl.py", line 3, in <module>
    fig = plt.figure(figsize=(0,0))
  File "/Users/kkolman/anaconda3/envs/sift/lib/python3.7/site-packages/matplotlib/pyplot.py", line 546, in figure
    **kwargs)
  File "/Users/kkolman/anaconda3/envs/sift/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3324, in new_figure_manager
    fig = fig_cls(*args, **kwargs)
  File "/Users/kkolman/anaconda3/envs/sift/lib/python3.7/site-packages/matplotlib/figure.py", line 349, in __init__
    raise ValueError('figure size must be positive finite not '
ValueError: figure size must be positive finite not (0, 0)

Expected outcome

The code above used to not raise an error in the previous version of matplotlib.

Matplotlib version

  • Operating system: macOS 10.14.6
  • Matplotlib version: 3.2.0
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.7.6

Matplotlib installation:

conda install -c conda-forge matplotlib

cc @djhoese

@djhoese
Copy link

djhoese commented Mar 5, 2020

This was brought up on gitter as something that maybe shouldn't be raising an error.

@tacaswell
Copy link
Member

This looks like it was an intentional change (see #13859) to avoid crashes down-stream when trying to save 0 sized images into png. We didn't put an API change note in for this because it was a bug fix and we did not think there was a valid use of a 0 size figure in the wild.

Given that @djhoese gitter you said this was a test making sure your code behaved correctly in the case of nonsensical input I hope that you can just stoy worrying about that case ;)

Is there a use-case for a 0 size figure? If there is not, I propose closing this as no-action (or maybe add a retro-active API change notice).

Thank you for reporting this @katherinekolman

@djhoese
Copy link

djhoese commented Mar 5, 2020

Is there a use-case for a 0 size figure?

Not that I know of but I'm definitely not the person who should have the final answer on that. I could see someone doing it for testing but at that point just make a 1x1 image if you need to.

I would say this is not an issue for my team anymore. We removed the test which itself was a test of another thing that was nonsensical. Feel free to close.

@QuLogic
Copy link
Member

QuLogic commented Jun 16, 2020

This is now actually allowed from #17610.

@QuLogic QuLogic added this to the v3.3.0 milestone Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants