Skip to content

Instantly share code, notes, and snippets.

@joferkington
Created February 21, 2014 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joferkington/9138655 to your computer and use it in GitHub Desktop.
Save joferkington/9138655 to your computer and use it in GitHub Desktop.
I'm having a bit too much fun with this...
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))
inception(inception(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):
data = fig2rgb_array(fig)
fig.clf()
fig.add_subplot(111).imshow(data)
return fig
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment