gpt4 book ai didi

python - 获取最大化 matplotlib 图的大小

转载 作者:行者123 更新时间:2023-12-04 09:44:12 24 4
gpt4 key购买 nike

我想打开一个最大化的 matplotlib 图形,我想以英寸为单位获得图形的大小。无论数字是否最大化,这都会产生相同的值:

import matplotlib.pyplot as plt

# figManager = plt.get_current_fig_manager()
# figManager.window.showMaximized()

fig = plt.gcf()
height = fig.get_size_inches()[1]
print(height)
4.8

任何提示?

最佳答案

我怀疑这是由于最大化/绘制图形本身所需的时间。在调整大小之前,您可能会捕捉到图形的大小。

引入任意长度的暂停可以解决问题:

import matplotlib.pyplot as plt

figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()

plt.pause(0.0001)

fig = plt.gcf()
height = fig.get_size_inches()[1]
print(height)
# 9.56 Commenting out the pause gives me the result 4.8

关于python - 获取最大化 matplotlib 图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62195970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com