JuliaCloud / JuliaBox

Juliabox continues to run, but this codebase is no longer current.
http://www.juliabox.org/
Other
185 stars 50 forks source link

Python2 notebook: matplotlib.pyplot.plot "no $DISPLAY" #352

Open NHDaly opened 8 years ago

NHDaly commented 8 years ago

I'm running a Python2 Notebook on a JuliaBox instance, and trying to plot with matplotlib. I copied this code from matplotlib's documentation, but saw this Exception:

---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
<ipython-input-166-c03a992e4fcd> in <module>()
      3 x = np.arange(0, 5, 0.1);
      4 y = np.sin(x)
----> 5 plt.figure()
      6 plt.plot(x, y)

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
    421                                         frameon=frameon,
    422                                         FigureClass=FigureClass,
--> 423                                         **kwargs)
    424 
    425         if figLabel:

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
     77     FigureClass = kwargs.pop('FigureClass', Figure)
     78     figure = FigureClass(*args, **kwargs)
---> 79     return new_figure_manager_given_figure(num, figure)
     80 
     81 

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
     85     """
     86     _focus = windowing.FocusManager()
---> 87     window = Tk.Tk()
     88     window.withdraw()
     89 

/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
   1765                 baseName = baseName + ext
   1766         interactive = 0
-> 1767         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   1768         if useTk:
   1769             self._loadtk()

TclError: no display name and no $DISPLAY environment variable

The important point here is it doesn't think it's connected to the display. Julia notebooks are able to display onto the HTML output somehow. Can the Python2 notebooks do the same thing? :) Thanks!

daiki8 commented 7 years ago

You can plot it by adding %pylab inline --no-import-all your code. For Example:

%pylab inline --no-import-all

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.figure()
plt.plot(x, y)