0

I have a Canvas class that inherits from the FigureCanvas class in Matplotlib.

from matplotlib.backends.backend_qt5agg import FigureCanvas
class Canvas(FigureCanvas):
    def __init__(self):
        fig = Figure(figsize=(5, 3))
        super().__init__(fig)

And I display canvas figures in the PyQt5 window. The canvas size changes depending on the size of the window. When I print these canvases, it always prints at the current size of the canvas (solutions in How do I change the size of figures drawn with Matplotlib? and Specify figure size in centimeter in matplotlib do not work).

However, I would like to print them in a fixed size, no matter what the current size is. As far as I could tell from the internet, I cannot specify size in print_figure() function. How can I print all the figures at the fixed size?

  • This is irreproducible, but `fig.set_figsize_inches(5,3), fig.savefig('Boo.png')` doesn't work? Its hard to understand why that would be, except if your GUI is forcing the fig size to change in a closed loop somehow – Jody Klymak Jan 06 '23 at 20:14
  • @JodyKlymak Unfortunately no, it does not save the fig specified size. I couldn't put full code since it is too long but, indeed, GUI Is forcing the figures to change their size on the window. However, I still want to save them `figsize=(5, 3)` even if their size is changed on GUI. – justRandomLearner Jan 23 '23 at 16:36

0 Answers0