出于某种原因,这段代码创建了一个只有标准尺寸的图形:它不会改变高度或宽度(我选择了荒谬的宽度和高度来清楚地说明问题):
import matplotlib.pyplot as plt
fig = plt.figure()
fig.set_figwidth(30)
fig.set_figheight(1)
print('Width: {}'.format(fig.get_figwidth()))
plt.show()
我在 OSX 10.10.4、Python 3.4.3、Matplotlib 1.4.3 上运行。 (通过 Macports 安装。)有什么想法吗?我错过了什么?
最佳答案
可选参数 forward
将更改传播到 已经存在 的 GUI 窗口中的 Canvas 。
optional kwarg
forward=True
will cause the canvas size to be automatically updated; e.g., you can resize the figure window from the shell
使用 Figure(figsize=(w,h))
也可以。
对于 Matplotlib 2.2.0 及更新版本
forward=True
是所有三个 set_figheight
的默认值, set_figwidth
, 和 set_size_inches
(set_size_inches
同时更改高度和宽度)。
对于 Matplotlib 1.5.0
forward=True
必须明确指定,因为它默认为 False
。 (在 Matplotlib 2.0.0 中,对于 set_size_inches
,默认值更改为 True
only)。
对于 Matplotlib 1.4.3 及更早版本
forward
仅受 set_size_inches
支持。
set_figheight
和 set_figwidth
不支持这个论点,所以只改变一个预先创建的GUI的单一维度有点困难。
关于python - 使用 set_fig(width/height) 调整 matplotlib 图的大小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31841289/