Skip to content

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

Closed

Description

@katherinekolman

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

Activity

  1. djhoese commented on Mar 5, 2020

    @djhoese

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

  2. tacaswell commented on Mar 5, 2020

    @tacaswell
    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

  3. djhoese commented on Mar 5, 2020

    @djhoese

    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.

  4. QuLogic commented on Jun 16, 2020

    @QuLogic
    Member

    This is now actually allowed from #17610.

  5. added this to the v3.3.0 milestone on Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions