gpt4 book ai didi

python - 在 matplotlib 中指定子图大小而不是 figsize

转载 作者:太空宇宙 更新时间:2023-11-04 03:12:40 29 4
gpt4 key购买 nike

我正在使用 matplotlib 绘制一些图形。通常,标准做法是从图形的尺寸开始并指定轴的尺寸,以便图形随后缩放到可用空间。

但是我有一个请求来扩展图表的高度以容纳 y 轴上的异常数据。

我知道我可以使用 Figure.figsize 来指定整体尺寸,但是一旦包含边距,这将无法使图表保持比例。有没有一种方法可以指定实际的子图大小或相反地确定默认边距大小的边距大小并相应地调整图形的尺寸?

最佳答案

你的意思是这样的?您需要计算利润率。

import matplotlib.pyplot as plt

subplotsize=[5.,5.]
figuresize=[10.,10.]

left = 0.5*(1.-subplotsize[0]/figuresize[0])
right = 1.-left
bottom = 0.5*(1.-subplotsize[1]/figuresize[1])
top = 1.-bottom
fig=plt.figure(figsize=(figuresize[0],figuresize[1]))
fig.subplots_adjust(left=left,right=right,bottom=bottom,top=top)
ax=fig.add_subplot(111)
plt.show()

关于python - 在 matplotlib 中指定子图大小而不是 figsize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37493498/

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