0

I am creating plots using matplotlib and mpld3 (both successfully installed) but when plotting I got this error message:

...File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in init#012 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)#012TclError: no display name and no $DISPLAY environment variable.

Any idea how to solve that? thanks for your help

1
  • Thanks! it was the right thing to add. Commented Sep 1, 2017 at 15:24

1 Answer 1

2

Try this

import matplotlib
matplotlib.use('Agg')

Check this page for more informations

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

4 Comments

PythonAnywhere dev here -- +1 to that! Here's the relevant help page
Hi again, sorry for the confusion. I still have the same error message. Maybe I am miss undestanding the example in the link but the advantage to use mpld3 with matplotlib is to display directly the generated figure in addition to the display options generated using mpld3 like zooming...In the example the figure must be saved and after the link is added so I will lose all the adavantages to use mpld3.
Ah, I see. The problem is that mpld3 is expecting to be running on a desktop computer with a display. Code on PythonAnywhere runs on a sever with no display, so it won't work. You can get similar stuff -- interactive charts and so on -- on PythonAnywhere, but you have to use IPython/Jupyter notebooks, which are a paid feature.
I Don't know how Jupyter will be a solution for what I want. In fact, the website offer the possibility to interact with an sql database via python/django and display plots and data according to the request. I dont know of saving the plot as json using mpld3 and after displaying it in a container will be a solution but I this is not an optimal solution as when different users made requests il will generate lot of plots that must be saved. Maybe I am wrong, I don't know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.