-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
- Matplotlib version, Python version and Platform (Windows, OSX, Linux ...) 1.5.1
- How did you install Matplotlib and Python -> pip
- If this is a regression (Used to work in an earlier version of Matplotlib), please
note where it used to work.
-> work on my windows and pycharm,but after I move it to a ubuntu and use docker to run it, it does not work.
Stackoverflow description:
Traceback (most recent call last):
File "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, _callback_args, *_callback_kwargs)
File "/code/fileUpload_app/views.py", line 174, in msa_result
result1 = generate_hist(db, *_processing_dict)
File "/code/fileUpload_app/post_processing.py", line 182, in generate_hist
fig1 = plt.figure()
File "/opt/conda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 527, in figure
*_kwargs)
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 46, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 53, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 76, in init
FigureCanvasQT.init(self, figure)
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py", line 68, in init
_create_qApp()
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 138, in _create_qApp
raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable
My code:
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
def generate_hist(db, **kwargs):
fig1 = plt.figure()
hist = mat2[0, 0:pin_num]
fig1 = plt.hist(hist)
plt.savefig("fileUpload_app/static/img/result/hist.jpg")