8000 figure created using figure.Figure doesn't save figure · Issue #12447 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
figure created using figure.Figure doesn't save figure #12447
Closed
@abbazs

Description

@abbazs

Figure object created using "from matplotlib import figure" is not able to save figure.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib import figure

def figure_bug(file):
    fig = figure.Figure(figsize=(2,5), constrained_layout=True)
    gs = gridspec.GridSpec(5, 1, figure=fig)
    axs = [fig.add_subplot(gs[x]) for x in range(1, 5)] 
    fig.text(0.5, 0.5, file, fontsize=25)
    fig.savefig(file)
    plt.close(fig)

if __name__ == '__main__':
    for i in range(0, 110):
        file_name = f'{i}.png'
        figure_bug(file_name)
        print(f'Done {i}')

Actual outcome

AttributeError Traceback (most recent call last)
D:\...\img_test\layou_test.py in <module>()
     14     for i in range(0, 110):
     15         file_name = f'{i}.png'
---> 16         figure_bug(file_name)
     17         print(f'Done {i}')

D:\....\img_test\layou_test.py in gridspec_bug(file)
      8     axs = [fig.add_subplot(gs[x]) for x in range(1, 5)]
      9     fig.text(0.5, 0.5, file, fontsize=25)
---> 10     fig.savefig(file)
     11     plt.close(fig)
     12

C:\....\matplotlib\figure.py in savefig(self, fname, frameon, transparent, **kwargs)
   2095             self.set_frameon(frameon)
   2096
-> 2097         self.canvas.print_figure(fname, **kwargs)
   2098
   2099         if frameon:

AttributeError: 'NoneType' object has no attribute 'print_figure'

Expected outcome
Saved image

Matplotlib version

  • Operating system: Windows
  • Matplotlib version: 3.0.0
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.5
  • Jupyter version (if applicable): NA
  • Other libraries: NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0