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

RuntimeError: Invalid DISPLAY variable #23

Closed
whliu90 opened this issue Nov 19, 2022 · 3 comments
Closed

RuntimeError: Invalid DISPLAY variable #23

whliu90 opened this issue Nov 19, 2022 · 3 comments

Comments

@whliu90
Copy link

whliu90 commented Nov 19, 2022

My code is as follows:

from RLA import MatplotlibRecorder as mpr
def plot_func():
    import matplotlib.pyplot as plt
    plt.switch_backend('agg')
    epochs_list = list(range(len(return_list1)))
    plt.plot(epochs_list, return_list1)
mpr.pretty_plot_wrapper('func', plot_func, xlabel='Epochs', ylabel='Match Pencentage', title='Test'

when runing on the command line, this runtime error happened:


File "/.../conda_pkgs/RLAssistant-main/RLA/easy_log/complex_data_recorder.py", line 65, in pretty_plot_wrapper
    plt.cla()
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3709, in cla
    ret = gca().cla()
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 959, in gca
    return gcf().gca(**kwargs)
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 588, in gcf
    return figure()
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 534, in figure
    **kwargs)
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 170, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 176, in new_figure_manager_given_figure
    canvas = cls.FigureCanvas(figure)
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 35, in __init__
    super(FigureCanvasQTAggBase, self).__init__(figure=figure)
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 235, in __init__
    _create_qApp()
  File "/data/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 122, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

could you help me to fix it?

@xionghuichen
Copy link
Collaborator

Hi, I have run a similar snippet in my workspace, but I cannot reproduce the error. specifically, I added ''plt.switch_backend('agg')'' in the unit test module after the line

import matplotlib.pyplot as plt
, and it works.

I surmise that the problem is caused by some mistakes outside of RLA.

Could it works if we just run the code

  import matplotlib.pyplot as plt
  plt.switch_backend('agg')
  epochs_list = list(range(len(return_list1)))
  plt.plot(epochs_list, return_list1)
  plt.savefig('test.png')

@whliu90
Copy link
Author

whliu90 commented Nov 21, 2022

When I run these codes

import matplotlib.pyplot as plt
# plt.switch_backend('agg')
epochs_list = list(range(len(return_list1)))
plt.plot(epochs_list, return_list1)
plt.savefig('test.png')

in two platforms, the codes work on both of them. However, once the code mpr.pretty_plot_wrapper('func', plot_func, xlabel='Epochs', ylabel='Match Pencentage', title='Test') added, these codes run well on just one of them. I also think it may be caused by other reasons unrelated to the RLA. I try to fix the problem with adding the line
plt.switch_backend('agg')
, which is a solution recommended on stackoverflow. Unfortunately, it seems that it doesn't work for this problem.

Nevermind, I have commented out these codes. Thank you very much!

@xionghuichen
Copy link
Collaborator

Cool! Then I will close the issue, and you can reopen it if you have any further questions.

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