python - 使用 set_fig(width/height) 调整 matplotlib 图的大小不起作用

标签 python matplotlib

出于某种原因,这段代码创建了一个只有标准尺寸的图形:它不会改变高度或宽度(我选择了荒谬的宽度和高度来清楚地说明问题):

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 。

Documentation here:

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_figheightset_figwidth不支持这个论点,所以只改变一个预先创建的GUI的单一维度有点困难。

关于python - 使用 set_fig(width/height) 调整 matplotlib 图的大小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31841289/

相关文章:

python - 将图像从笛卡尔坐标转换为极坐标 - 肢体变暗

python - 能否在 Bash 脚本或 Python 脚本中嵌入可由外部程序调用的 TCL 脚本?

python - 如何在 python 2.7 中为 TLS 套接字进行证书固定?

python - 从同一组的其他记录中的值替换 Pandas 数据框中的 NAN 值

python - Cloudwatch 代理错误 : No option 'file' in section: 'loggers'

Python matplotlib - Linux 上的大窗口

python - 如何使用 PyQt 组织布局

python - 使用 bokeh 或 matplotlib 的 Pandas DataFrame 分层饼图/ donut chart

python - 如何使用标准化标记透明度创建散点图

python - 如何在 matplotlib 中切换轴?