9

The thing preventing me from switching to cloud9 is the lack of support for matplotlib since graphing things are very important to my work.

I have tried installing matplotlib but there seems to be some problems with pygtk even though it appears to be installed. Is it even possible for an online ide to interact with gtk windows on my local computer? Perhaps the graphs could be generated remotely and saved to my directory?

It would be great if anyone had successfully managed this could show me how?

david_adler
  • 9,690
  • 6
  • 57
  • 97
  • I would look at the `webagg` backend for matplotlib. It is being developed to play nice with `ipython` notebooks. Letting a website reach in and grab window level control seems like a huge security issue to me. – tacaswell Feb 26 '13 at 15:25

2 Answers2

6

You can change the backend with

import matplotlib
matplotlib.use('Agg')

and then save the figure using figure.savefig('filename')

david_adler
  • 9,690
  • 6
  • 57
  • 97
  • On Cloud9 python: `matplotlib.use('Agg')` then `import matplotlib.pyplot as plt` then `fig, ax = plt.subplots(1,1)` results in TclError: no display name and no $DISPLAY environment variable – Bennett Brown Mar 01 '15 at 21:42
  • Ah: `use()` must be called before importing `pyplot`. – Bennett Brown Nov 22 '15 at 08:54
6

As indicated by David Adler, you can set a non-GUI backend:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt # Do not do this prior to calling use()

You can create a figure the usual way, except save it:

fig, ax = plt.subplots(1, 1)
ax.hist(numpy.random.randn(1000))
fig.savefig('display.svg') # Any filename will do

In Cloud9 you can open the SVG in a preview tab. Every time you update and save the figure, refresh the preview tab.

Bennett Brown
  • 5,234
  • 1
  • 27
  • 35