Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib Window Size, Title, etc

I'm new in python and matplotlib. I have a project and I need to create a graphic in a Tkinter GUI a graphic using matplotlib. I found and used this code:

import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd =   (2, 3, 4, 1, 2)

ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
womenStd =   (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)


ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )

ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )

def autolabel(rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
                ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)

plt.show()

But I can't find the way to change the size of the window that appears when I use this code. I have already try with this:

figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')

But this only creates another window! Help please!

like image 321
Cesar Borge Mora Avatar asked Mar 16 '23 05:03

Cesar Borge Mora


1 Answers

Simply replace

fig, ax = plt.subplots()

by:

fig, ax = plt.subplots(num=None, figsize=(16, 12), dpi=80, facecolor='w', edgecolor='k')
## I changed the fig size to something obviously big to make sure it worked

To change the title of the figure window, you can use:

fig.canvas.set_window_title('Test')
like image 73
Julien Spronck Avatar answered Mar 19 '23 06:03

Julien Spronck