Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

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

Open
NHDaly opened this issue Jan 6, 2016 · 1 comment
Open

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

NHDaly opened this issue Jan 6, 2016 · 1 comment

Comments

@NHDaly
Copy link
Contributor

NHDaly commented Jan 6, 2016

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
Copy link

daiki8 commented Dec 25, 2016

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants