【问题标题】:Python: Create subplots with plots generated by a "class"Python:使用“类”生成的图创建子图
【发布时间】:2020-10-26 18:47:00
【问题描述】:

我知道我想做什么,但我不确定如何提出这个问题。

在我的代码中,我使用 lightkurve 包,它有一个类 (lightkurve.lightcurve.TessLightCurve),它有一个方法 (plot) 可以绘制一个变量。 “plot”方法使用matplotlib。

通过这种方式,我可以绘制两个独立的图形,如下所示:

curve.plot()
plt.title("Merged unnormalized light curve \n nº of sectors merged: {0}".format(len(tpfs)))

corrected_curve.plot()
plt.title("Merged NORMALIZED light curve \n nº of sectors merged: {0}".format(len(tpfs)))

这给了我以下数字:

我想要做的是用这两个数字作为子图的单个图。 我知道如何使用matplotlib page 中描述的典型情节和子情节来做到这一点,但我不知道如何使用这种类型的数字来做到这一点:(

【问题讨论】:

    标签: python matplotlib plot subplot


    【解决方案1】:

    看起来像函数 lightkurve.lightcurve.TessLightCurve.plot() takes an argument ax= 来指示要使用哪个子图。

    fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1)
    curve.plot(ax=ax1)
    ax1.set_title("Merged unnormalized light curve \n nº of sectors merged: {0}".format(len(tpfs)))
    
    corrected_curve.plot(ax=ax2)
    ax2.set_title("Merged NORMALIZED light curve \n nº of sectors merged: {0}".format(len(tpfs)))
    

    【讨论】:

    • 非常感谢 Diziet!你们让事情变得如此简单。我会详细看一下,以便下次吸收和学习。谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 2012-02-15
    • 2021-01-23
    • 2018-10-21
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多