【问题标题】:Adding multiple Pull Plots with matplot lib使用 matplotlib 添加多个拉图
【发布时间】:2021-09-30 20:58:06
【问题描述】:

我在一个有拉图的情节中工作,我将其定义为:

fig, (ax1, ax2) = aplt.ratio_plot(name=  canvasArray[kl], figsize=(800, 800), hspace=0.05)

它工作正常,但现在我需要在图像中添加另一个拉图,所以我尝试了:

fig, (ax1, ax2,ax3) = aplt.subplots(3,1,name="fig1", figsize=(850, 950))

我得到了结果图:

我尝试了一些选项,例如 .set_aspect(),但我不断收到错误 AttributeError: 'Axes' object has no attribute 'set_aspect'。我希望主情节占全情节的 2/4,拉情节各占 1/2,但我对此有困难。

我在面向对象的环境中工作,所以我不知道这是否会改变事情。我正在使用使用 matplotlib 语法的 Atlasplots 包。 https://atlas-plots.readthedocs.io/en/latest/

【问题讨论】:

  • 我的环境下没试过,但是可以用下面的代码吗? fig, (ax1, ax2, ax3) = aplt.subplots(nrows=3,ncols=1,name="fig1",figsize=(850, 950), height_ratios=[2,1,1])我引用的信息是here

标签: python subplot atlas-plot


【解决方案1】:

我有个主意。 Matplotlib.pyplot 有一组参数,其中一个控制图的大小。它被称为:rcParams。这个属性内部是一个包含很多配置的字典。看看:

>>> from matplotlib import pyplot as plt
>>> plt.rcParams

如果你运行上面的代码行,你会得到the following。是的,这些东西很多,但我们有一个特定的密钥可以解决我们的问题。是"figure.figsize",如果你这样选择这个参数:

>>> plt.rcParams["figure.figsize"] = [6.0, 4.0]

您可以自定义绘图大小。因此,我认为您可以在代码中的某些位置使用它,并在需要时将其重置为默认值。

要查看默认值是什么,只需运行此命令以根据键 "figure.figsize" 获取输出:

>>> plt.rcParams["figure.figsize"]

[out]: ["your default", "values here"]

更新:2021 年 10 月 1 日

我刚想起来你也可以解压subplots(matplotlib.pyplot.subplots)直接选择参数,像这样:

>>> fig, ax = plt.subplots(figsize=("the size", "you want"))

我还注意到一些非常有趣的事情。如果您使用rcParams["figure.figsize"] 来控制绘图大小,它将在整个代码中保持不变,但如果您使用更新中显示的选项,则配置将仅适用于该绘图区域。这是我在这里观察到的一种行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多