0
votes

I am using matplotlib 2.2.2

Maximizing plot window not working after migrating to MPL 2.2.2.

I cannot figure out how to overcome this

on previous releases my code worked fine

from matplotlib.pyplot import *
import numpy as np


if __name__ == '__main__':

    x=np.linspace(0,1,100)
    y=x**2
    F1=figure()
    ax1=subplot(1, 1, 1)
    ax1.plot(x,y)
    F1.canvas.manager.window.showMaximized()
    show()

I am getting the blow code and window is not maximized:

"Traceback (most recent call last):

File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev\pydev_run_in_console.py", line 52, in run_file

pydev_imports.execfile(file, globals, locals)  # execute the script

File "max_fig.py", line 12, in F1.canvas.manager.window.showMaximized()

File "C:\IntelPython2\lib\lib-tk\Tkinter.py", line 1903, in getattr return getattr(self.tk, attr)

AttributeError: showMaximized"

2

2 Answers

2
votes

In your previous installation you used PyQt where showMaximized() is available.
In your new installation you are using Tkinter, which does not have a showMaximized().

Two options:

  1. Install PyQt for your new installation and use it e.g. via

    import matplotlib
    matplotlib.use("Qt5Agg")
    
  2. Keep working with Tkinter, but change your code to tk, i.e.

    F1.canvas.manager.frame.Maximize(True)
    

    or any other option listed in How to maximize a plt.show() window using Python

0
votes

Adding to the accepted answer, in case you are not using a Qt5 frontend, you can maximize by using:

fig = plt.gcf()
fig.set_size_inches( (666,666))