gpt4 book ai didi

python - Matplotlib 自动图异常(exception)图

转载 作者:太空狗 更新时间:2023-10-29 16:53:03 28 4
gpt4 key购买 nike

<分区>

我正在尝试在 Python 的 matplotlib 图中使用关键字 bbox_to_anchor()

这是我制作的一个非常基本的情节 based on this example . :

import matplotlib.pyplot as plt
x = [1,2,3]
plt.subplot(211)
plt.plot(x, label="test1")
plt.plot([3,2,1], label="test2")
plt.legend(bbox_to_anchor=(0, -0.15, 1, 0), loc=2, ncol=2, mode="expand", borderaxespad=0)
plt.show()

我正在尝试使用 bbox_to_anchor() 自动将图例放置在绘图之外。在此示例中,bbox_to_anchor() 列出了 4 个参数。

在这个特定示例(上图)中,图例位于图下方,因此每次更改图(字体大小、轴标题已删除等)时都需要手动输入数字 -0.15。是否可以针对以下场景自动计算这 4 个数字?:

  1. 情节下方的传说
  2. 情节上方的传说
  3. 情节右侧的图例

如果不是,是否有可能在 Python 中对这些数字做出正确的猜测?

此外,在上面的示例代码中,我将 bbox_to_anchor() 中的最后两个数字设置为 1 和 0,因为我不明白它们是什么或它们是如何工作的。 bbox_to_anchor() 中的最后两个数字是什么意思?

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