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

Brown Bear
  • 19,655
  • 10
  • 58
  • 76
Bioinfo
  • 51
  • 5

1 Answers1

2

Try this

import matplotlib
matplotlib.use('Agg')

Check this page for more informations

user10089632
  • 5,216
  • 1
  • 26
  • 34
  • 1
    PythonAnywhere dev here -- +1 to that! Here's [the relevant help page](https://help.pythonanywhere.com/pages/MatplotLibGraphs) – Giles Thomas Sep 01 '17 at 14:37
  • 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. – Bioinfo Sep 01 '17 at 18:29
  • 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. – Giles Thomas Sep 01 '17 at 18:40
  • 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 – Bioinfo Sep 01 '17 at 19:51