我正在使用matplotlib 2.2.2
迁移到MPL 2.2.2后,最大化绘图窗口不起作用
我不知道该如何克服
在以前的版本中,我的代码运行正常
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()
我得到的打击代码和窗口未最大化:
“追踪(最近通话最近):
run_file中的文件“ C:\ Program Files \ JetBrains \ PyCharm Community Edition 2018.1.2 \ helpers \ pydev \ pydev_run_in_console.py”,第52行
pydev_imports.execfile(file, globals, locals) # execute the script
文件“ max_fig.py”,第12行 F1.canvas.manager.window.showMaximized()
getattr 中的文件“ C:\ IntelPython2 \ lib \ lib-tk \ Tkinter.py”,行1903 返回getattr(self.tk,attr)
AttributeError:showMaximized”
答案 0 :(得分:2)
在先前的安装中,您使用了showMaximized()
可用的PyQt。
在新安装中,您正在使用Tkinter,它没有import matplotlib
matplotlib.use("Qt5Agg")
。
两个选项:
为新安装安装PyQt并使用它,例如通过
F1.canvas.manager.frame.Maximize(True)
继续使用Tkinter,但将代码更改为tk,即
static string AddNumStr(string v1, string v2)
{
var v1Len = v1.Length;
var v2Len = v2.Length;
var count = Math.Max(v1Len, v2Len);
var answ = new char[count + 1];
while (count >= 0) answ[count--] = (char)((v1Len > 0 ? v1[--v1Len] & 0xF:0) + (v2Len>0 ? v2[--v2Len]&0xF : 0));
for (var i = answ.Length - 1; i >= 0; i--)
{
if (answ[i] > 9)
{
answ[i - 1]++;
answ[i] -= (char)10;
}
answ[i] = (char)(answ[i] | 48);
}
return new string(answ).TrimStart('0');
}
或列在其中的任何其他选项 How to maximize a plt.show() window using Python
答案 1 :(得分:0)
在不使用Qt5前端的情况下,添加到已接受的答案中,可以使用以下方法最大化:
fig = plt.gcf()
fig.set_size_inches( (666,666))