There’s a bad meme here. Hope you’ll forgive the distraction!
import matplotlib.pyplot as plt
import numpy as np
def main():
t = np.linspace(0, 4*np.pi, 1000)
fig, ax = plt.subplots()
ax.plot(t, np.cos(t))
ax.plot(t, np.sin(t))
for _ in range(10):
fig = inception(fig)
plt.show()
def fig2rgb_array(fig):
fig.canvas.draw()
buf = fig.canvas.tostring_rgb()
ncols, nrows = fig.canvas.get_width_height()
return np.fromstring(buf, dtype=np.uint8).reshape(nrows, ncols, 3)
def inception(fig):
fig.tight_layout()
fig.set_facecolor('white')
data = fig2rgb_array(fig)
fig.clf()
fig.add_subplot(111).imshow(data)
return fig
main()