1

While importing and attempting the following:

import matplotlib
from matplotlib import pyplot as plt


plt.plot([1,2,3],[1,4,9])
plt.show()

I get the following error. How do I fix? I am running Python 2.7, and notebook version 4.1.0. Thank you.

RuntimeError: Invalid DISPLAY variable
heisenberg
  • 47
  • 1
  • 7
  • it's possible that you're using it with a different users from the one that is running the X subsystem. Try using the same user. Otherwise, as a quick workaround and provided that you have a single display, try this before running your script: **export DISPLAY=:0** – Davide Alberani Aug 21 '17 at 07:31
  • 1
    Do you by chance run the Python remotely on another computer via SSH? – DYZ Aug 21 '17 at 07:46
  • export DISPLAY=:0 gives invalid syntax. Is it =:0? Thank you. – heisenberg Aug 21 '17 at 07:47
  • The jupyter notebook reside on linux server and I am using the chrome browser to work in the notebooks. – heisenberg Aug 21 '17 at 07:48

1 Answers1

3

When running a jupyter notebook on a server, the server may not even be able to display the plot. The usual solution would be to use a non-interactive backend. In case of a jupyter notebook this would be done by adding

%matplotlib inline

at the top of the notebook, such that graphics are shown as png images.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712