I want to merge two axes that have been created as follows:
xx = np.arange(12)
fig1, ax1 = plt.subplots()
ax1.plot(xx, 2*xx, label="V1")
fig2, ax2 = plt.subplots()
ax2.plot(xx, 1.2*xx, label="V2")
Suppose I no longer have access to the code used to create these plots, but just to fig1, ax1, fig2, ax2 objects (e.g. via pickling).
The two plots should be merged such that the output is (visually) the same (up to colors) as the output of:
fig, ax = plt.subplots()
ax.plot(xx, 2*xx, label="V1")
ax.plot(xx, 1.2*xx, label="V2")
I have tried
ax.lines += ax2.lines
# or
ax.add_artist(ax2.lines[0])
but this gives Can not reset the axes. You are probably trying to re-use an artist in more than one Axes which is not supported.
How can I copy the lines from one figure to the other?
source https://stackoverflow.com/questions/75061799/combine-two-pyplot-axis-into-single-axis



Comments
Post a Comment