I have this code to plot
import matplotlib.pyplot as plt
import numpy as np
# Data
time = np.arange(0,20,0.05)
data = np.sin(time)
# Plot
main_plot = plt.plot(time, data)
error_plot = plt.fill_between(time, data+0.5, data-0.5, alpha=0.2)
plt.show()
and I would like to plot, after in the code, the same plot but using the main_plot
and error_plot
variable. So I have this
plt.plot(*main_plot[0].get_data())
# Here I want to plot the error_plot (PolyCollection type)
# but I don't know how. Something like
# plt.plot(error_plot)
I have tried this related post with no result. I've also tried
fig = plt.figure()
ax = fig.add_subplot(111)
ax.add_collection(error_plot)
but resulting in this error
1 fig = plt.figure()
2 ax = fig.add_subplot(111)
----> 3 ax.add_collection(error_plot)
RuntimeError: Can not put single artist in more than one figure