Danirevis
Danirevis

Reputation: 13

Python: Create subplots with plots generated by a "class"

I know what I want to do but I'm not sure how to make this question.

In my code I'm using lightkurve package, which has a class (lightkurve.lightcurve.TessLightCurve) that has a method (plot) that plots the content of a variable. The "plot" method uses matplotlib.

In this way, I'm able to plot two independent figures like the following:

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)))

That give me the following figures:

Figure 1 Figure 2

What I want to do is to have a single plot with those two figures as subplots. I know how to do it with typical plots and subplots like the ones described in the matplotlib page, but I've no idea how to do it with this type of figures :(

Upvotes: 0

Views: 210

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40707

Looks like the function lightkurve.lightcurve.TessLightCurve.plot() takes an argument ax= to instruct which subplot to use.

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)))

Upvotes: 1

Related Questions