How to enlarge plt.show () window using Python

Just for curiosity, I would like to know how to do this in the code below. I was looking for an answer, but useless.

import numpy as np import matplotlib.pyplot as plt data=np.random.exponential(scale=180, size=10000) print ('el valor medio de la distribucion exponencial es: ') print np.average(data) plt.hist(data,bins=len(data)**0.5,normed=True, cumulative=True, facecolor='red', label='datos tamano paqutes acumulativa', alpha=0.5) plt.legend() plt.xlabel('algo') plt.ylabel('algo') plt.grid() plt.show() 
+70
python matplotlib
Sep 15
source share
19 answers

I usually use

 mng = plt.get_current_fig_manager() mng.frame.Maximize(True) 

before calling plt.show() , and I get a maximized window. This only works for the 'wx' backend.

EDIT:

for the Qt4Agg backend, see kwerenda answer .

+27
Sep 26 '12 at 9:53 on
source share

since I am on zero reputation, I cannot leave any other sign than the new answer. I am on Windows (WIN7), starting Python 2.7.5 and Matplotlib 1.3.1

I managed to maximize the Figure windows for TkAgg, QT4Agg and wxAgg using the following lines:

 from matplotlib import pyplot as plt ### for 'TkAgg' backend plt.figure(1) plt.switch_backend('TkAgg') #TkAgg (instead Qt4Agg) print '#1 Backend:',plt.get_backend() plt.plot([1,2,6,4]) mng = plt.get_current_fig_manager() ### works on Ubuntu??? >> did NOT working on windows # mng.resize(*mng.window.maxsize()) mng.window.state('zoomed') #works fine on Windows! plt.show() #close the figure to run the next section ### for 'wxAgg' backend plt.figure(2) plt.switch_backend('wxAgg') print '#2 Backend:',plt.get_backend() plt.plot([1,2,6,4]) mng = plt.get_current_fig_manager() mng.frame.Maximize(True) plt.show() #close the figure to run the next section ### for 'Qt4Agg' backend plt.figure(3) plt.switch_backend('QT4Agg') #default on my system print '#3 Backend:',plt.get_backend() plt.plot([1,2,6,4]) figManager = plt.get_current_fig_manager() figManager.window.showMaximized() plt.show() 

We hope that this summary of previous answers (and some additions), combined in a working example (at least for Windows), helps. Greetings

+133
Mar 15 '14 at 1:12
source share

Qt backend native command (FigureManagerQT):

 figManager = plt.get_current_fig_manager() figManager.window.showMaximized() 
+59
Sep 16 '13 at 9:39 on
source share

This makes the window for me a full screen for me, under Ubuntu 12.04 with the TkAgg backend:

  mng = plt.get_current_fig_manager() mng.resize(*mng.window.maxsize()) 
+35
Jan 26 '13 at 13:10
source share

For me, none of this was. I am using Tk backend on Ubuntu 14.04 which contains matplotlib 1.3.1.

The following code creates a full-screen graph window that does not match maximization, but it perfectly fulfills my purpose:

 from matplotlib import pyplot as plt mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show() 
+32
May 20 '14 at 8:59
source share

This should work (at least with TkAgg):

 wm = plt.get_current_fig_manager() wm.window.state('zoomed') 

(adopted from the above and Using Tkinter, is there a way to get the screen size for ease of use without a visible enlargement of the window?

+25
Nov 06 '13 at 22:08
source share

I get mng.frame.Maximize(True) AttributeError: FigureManagerTkAgg instance has no attribute 'frame' .

Then I looked at the mng has attributes, and I found this:

 mng.window.showMaximized() 

It worked for me.

So, for people who have the same problem, you can try this.

By the way, my version of Matplotlib is 1.3.1.

+5
Dec 17 '13 at 0:06
source share

I found this for fullscreen in Ubuntu

 #Show full screen mng = plt.get_current_fig_manager() mng.full_screen_toggle() 
+5
Mar 09 '19 at 19:25
source share

This is a kind of hacker and probably not portable, use it only if you are looking for a quick and dirty one. If I just set the figure much larger than the screen, it occupies exactly the entire screen.

 fig = figure(figsize=(80, 60)) 

In fact, on Ubuntu 16.04 with Qt4Agg, it maximizes the window (not full screen) if it is larger than the screen. (If you have two monitors, it just maximizes it on one of them).

+4
Dec 02 '16 at 10:37
source share

Try plt.figure(figsize=(6*3.13,4*3.13)) to make the graph larger.

+2
Sep 15 '12 at 17:37
source share

When you press f (or ctrl+f in 1.2rc1) while focusing on the chart, a full-screen chart window will be displayed. Not really maximization, but perhaps better.

In addition, to maximize the maximum values, you will need to use special GUI Toolkit commands (if they exist for your specific backend).

NTN

+2
Sep 16 '12 at 7:14
source share

Try using the Figure.set_size_inches method with the optional forward=True key argument. According to the documentation , this should resize the drawing window.

Whether this actually happens will depend on the operating system you are using.

+2
Sep 16 '12 at 15:43
source share

In my versions (Python 3.6, Eclipse, Windows 7) the above snippets did not work, but with the hints given by Eclipse / pydev (after entering: mng.), I found:

 mng.full_screen_toggle() 

It seems that using mng commands is ok only for local development ...

+2
Apr 18 '18 at 6:35
source share

Ok, so this is what worked for me. I made the entire showMaximize () parameter, and it resizes your window in proportion to the size of the figure, but it does not expand and does not fit the canvas. I solved this:

 mng = plt.get_current_fig_manager() mng.window.showMaximized() plt.tight_layout() plt.savefig('Images/SAVES_PIC_AS_PDF.pdf') plt.show() 
+1
Nov 05 '16 at 10:42 on
source share

The only solution that worked on Win 10 flawlessly.

 import matplotlib.pyplot as plt plt.plot(x_data, y_data) mng = plt.get_current_fig_manager() mng.window.state("zoomed") plt.show() 
+1
Nov 23 '18 at 15:21
source share

My best efforts at the moment, support for different backends:

 from platform import system def plt_maximize(): # See discussion: https://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python backend = plt.get_backend() cfm = plt.get_current_fig_manager() if backend == "wxAgg": cfm.frame.Maximize(True) elif backend == "TkAgg": if system() == "win32": cfm.window.state('zoomed') # This is windows only else: cfm.resize(*cfm.window.maxsize()) elif backend == 'QT4Agg': cfm.window.showMaximized() elif callable(getattr(cfm, "full_screen_toggle", None)): if not getattr(cfm, "flag_is_max", None): cfm.full_screen_toggle() cfm.flag_is_max = True else: raise RuntimeError("plt_maximize() is not implemented for current backend:", backend) 
+1
Feb 15 '19 at 11:46
source share

This does not necessarily maximize your window, but it resizes your window in proportion to the size of the shape:

 from matplotlib import pyplot as plt F = gcf() Size = F.get_size_inches() F.set_size_inches(Size[0]*2, Size[1]*2, forward=True)#Set forward to True to resize window along with plot in figure. plt.show() #or plt.imshow(z_array) if using an animation, where z_array is a matrix or numpy array 

It may also help: http://matplotlib.1069221.n5.nabble.com/Resizing-figure-windows-td11424.html

0
May 28 '14 at 5:43
source share

The following steps can work with all backends, but I tested them only on QT:

 import numpy as np import matplotlib.pyplot as plt import time plt.switch_backend('QT4Agg') #default on my system print('Backend: {}'.format(plt.get_backend())) fig = plt.figure() ax = fig.add_axes([0,0, 1,1]) ax.axis([0,10, 0,10]) ax.plot(5, 5, 'ro') mng = plt._pylab_helpers.Gcf.figs.get(fig.number, None) mng.window.showMaximized() #maximize the figure time.sleep(3) mng.window.showMinimized() #minimize the figure time.sleep(3) mng.window.showNormal() #normal figure time.sleep(3) mng.window.hide() #hide the figure time.sleep(3) fig.show() #show the previously hidden figure ax.plot(6,6, 'bo') #just to check that everything is ok plt.show() 
0
Feb 10 '16 at 8:46
source share

Here is a function based on @Pythonio's answer. I encapsulate it in a function that automatically determines which backend it uses and performs the appropriate actions.

 def plt_set_fullscreen(): backend = str(plt.get_backend()) mgr = plt.get_current_fig_manager() if backend == 'TkAgg': if os.name == 'nt': mgr.window.state('zoomed') else: mgr.resize(*mgr.window.maxsize()) elif backend == 'wxAgg': mgr.frame.Maximize(True) elif backend == 'Qt4Agg': mgr.window.showMaximized() 
0
Sep 26 '19 at 0:44
source share



All Articles