【问题标题】:Matplotlib Window Size, Title, etcMatplotlib 窗口大小、标题等
【发布时间】:2015-07-11 01:26:49
【问题描述】:

我是 python 和 matplotlib 的新手。我有一个项目,我需要在 Tkinter GUI 中创建一个使用 matplotlib 的图形。我找到并使用了这段代码:

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()

但我找不到更改使用此代码时出现的窗口大小的方法。 我已经尝试过:

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

但这只会创建另一个窗口!请帮忙!

【问题讨论】:

    标签: python matplotlib figure


    【解决方案1】:

    简单替换

    fig, ax = plt.subplots()
    

    作者:

    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
    

    要更改图形窗口的标题,可以使用:

    fig.canvas.set_window_title('Test')
    

    【讨论】:

    • 这对我帮助很大!!你知道如何更改窗口标题和图标吗?
    • @CesarBorgeMora 我用如何更改窗口标题编辑了我的答案。对于图标,我不知道,但请查看以下问题:stackoverflow.com/questions/10189590/…。随时接受我的回答来表达你的感激之情:-)
    猜你喜欢
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    相关资源
    最近更新 更多