Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless plotting? #1

Open
sfeister opened this issue Nov 3, 2017 · 2 comments
Open

Headless plotting? #1

sfeister opened this issue Nov 3, 2017 · 2 comments

Comments

@sfeister
Copy link

sfeister commented Nov 3, 2017

Headless plotting is not implemented; currently requires X11 forwarding if running on a server.

Traceback

 (most recent call last):
  File "prorad.py", line 734, in <module>
    main()
  File "prorad.py", line 78, in main
    plot_results(grid, film_x, film_y, Ep, traces, plot_fluence=True, plot_traces=True, plot_quiver=False, save_images=True)
  File "prorad.py", line 665, in plot_results
    fig = plt.figure(2,figsize=(8,8))
  File "/software/python-2.7.12-el7-x86_64/lib/python2.7/site-packages/matplotlib/pyplot.py", line 535, in figure
    **kwargs)
  File "/software/python-2.7.12-el7-x86_64/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/software/python-2.7.12-el7-x86_64/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/software/python-2.7.12-el7-x86_64/lib/python2.7/lib-tk/Tkinter.py", line 1815, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:16.0"

This could be corrected using the matplotlib 'Agg' plotter, which would also suppress GUI popups. I'll see about pushing a change.

@sfeister
Copy link
Author

sfeister commented Nov 3, 2017

I confirmed that this issue can be fixed by editing the prorad.py header:

Before (X11 required):

...
import matplotlib.pyplot as plt
...

After (headless plotting):

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

@deuterium33
Copy link

deuterium33 commented Nov 15, 2017

One way of having this detected automatically (in Unix platforms at least) is to do :

import matplotlib as mpl
import os
if not os.environ.has_key('DISPLAY'):
    mpl.use('Agg')
import matplotlib.pyplot as plt

Best,
Mathieu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants