When I want to make several subplots in a figure I can do, for example, the following
figA=plt.figure('figA',figsize=(30,25))
(ax2,ax1) = figA.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
And I can then make the plot using ax2.plot(data2)
and ax1.plot(data1)
Then I might want to do another separate figure:
figB=plt.figure('figB',figsize=(30,25))
(ax2B,ax1B) = figB.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
However, I need the exact same top panel as in the previous figure.
What should I do if I want ax2B
to always be identical to ax2
, no matter what changes I make to the subplot?
In other words, I would like to define a subplot and apply it to several figures, rather than defining it inside a specific figure.
If for example in the top panel I want a straight line f(x)=x
, I will do
import numpy as np
X=np.linspace(0.,10.,10)
ax2.plot(X,X)
ax2B.plot(X,X)
but I do not want to define the exact same plot twice. I want to just define a subplot once and for all and then call it in a new figure when I need it.