2

I have been through many post talking about this issue but haven't find anything working on my server. So I am working on a server, on which I don't have a sudo access. I am simply trying to produce plots with matplotlib but I get the infamous

TclError: no display name and no $DISPLAY environment variable

I tried this ;

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)


# basic plot
plt.boxplot(data) ##############Crash here

plt.savefig( 'output_filename.png' )

But I can't plot at all. Is there anyway to work around that,without involving installing system packages (I can pip install if needed). I am creating a command line tool for some other users so I need something without too much modification. I am using ipython for troubleshooting but get the same error when running with

python name_of_script.py

Thanks for looking into it.

  • Where are you expecting the graph to show up? – that other guy Nov 11 '15 at 23:17
  • `plt.boxplot` won't do much by itself. Do you have `plt.show` or `plt.savefig` somewhere in your code after that? You should be using `plt.savefig` at least, not `plt.show`. –  Nov 11 '15 at 23:20
  • To amend my previous comment: you may have interactivity set to on (I think that's `plt.ion()` or similar). I'm not sure what exactly would happen in a combination of a non-interactive backend and an interactive matplotlib setting, but possible it could lead to this error. –  Nov 11 '15 at 23:22
  • It doesn't go pass the plt.boxplot, which is why I don't have anything after. This is just a reproducible example for me to troubleshoot. My actual code has plt.savefig. – User18981898198119 Nov 11 '15 at 23:25
  • Check your mpl configuration file, to see if there's any interactivity setting there that is turned on. –  Nov 11 '15 at 23:31
  • I got the script above to work on the server. But the real script still doesn't work. Could it be because of libraries such as seaborn? – User18981898198119 Nov 11 '15 at 23:48
  • Working now, I have no idea why. Maybe because I was importing seaborn before matplotlib... Anyway thank you – User18981898198119 Nov 12 '15 at 00:00

0 Answers0