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
4
  • 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 Commented Aug 21, 2017 at 7:31
  • 1
    Do you by chance run the Python remotely on another computer via SSH? Commented Aug 21, 2017 at 7:46
  • export DISPLAY=:0 gives invalid syntax. Is it =:0? Thank you. Commented Aug 21, 2017 at 7:47
  • The jupyter notebook reside on linux server and I am using the chrome browser to work in the notebooks. Commented Aug 21, 2017 at 7:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.