Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maximize a plt.show() window using Python

Just for curiosity I would like to know how to do this in the code below. I have been searching for an answer but is 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() 
like image 667
Santiago Lovera Avatar asked Sep 15 '12 17:09

Santiago Lovera


People also ask

How do I make matplotlib full screen?

To show matplotlib graphs as full screen, we can use full_screen_toggle() method.

How do I change the window size in matplotlib?

For all backends, the window size is controlled by the figsize argument. In general, for any matplotlib figure object, you can also call fig. set_size_inches((width, height)) to change the size of the figure.


Video Answer


2 Answers

I am on a Windows (WIN7), running Python 2.7.5 & Matplotlib 1.3.1.

I was able to maximize 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() 

if you want to maximize multiple figures you can use

for fig in figs:     mng = fig.canvas.manager     # ... 

Hope this summary of the previous answers (and some additions) combined in a working example (at least for windows) helps. Cheers

like image 154
Pythonio Avatar answered Sep 28 '22 04:09

Pythonio


With Qt backend (FigureManagerQT) proper command is:

figManager = plt.get_current_fig_manager() figManager.window.showMaximized() 
like image 28
kwerenda Avatar answered Sep 28 '22 04:09

kwerenda