RuntimeError: Invalid DISPLAY variable
You must declare matplotlib.use('agg')
before import pylab as plt
.
Reference
docker/matplotlib: RuntimeError: Invalid DISPLAY variable
The reason is that I import seaborn
before I import matplotlib
. This caused matplotlib not running in the right place.
matplotlib pyplot Invalid DISPLAY variable
When running a jupyter notebook on a server, the server may not even be able to display the plot. The usual solution would be to use a non-interactive backend. In case of a jupyter notebook this would be done by adding
%matplotlib inline
at the top of the notebook, such that graphics are shown as png images.
plotting without display: correct use of matplotlib.use()
You need to
import matplotlib
matplotlib.use('Agg')
on a fresh kernel, especially if you are using ipython
, before importing matplotlib.pyplot
I'd be curious, and happy, to know if there are ways to clear/flush the ipython kernel, without having to restart it; so far, my quest has not been successful.
Related Topics
Total Memory Used by Python Process
Command 'X86_64-Linux-Gnu-Gcc' Failed with Exit Status 1
Simulate Mouse Clicks on Python
Pip Is Not Working for Python 3.10 on Ubuntu
How to Create a User in Linux Using Python
Multiple Instances of Python Running Simultaneously Limited to 35
What Is the Easiest Way to Detect Key Presses in Python 3 on a Linux MAChine
How to Find the Mountpoint a File Resides On
Read File with Timeout in Python
How to Push a Subprocess.Call() Output to Terminal and File
Run a Python Script in Terminal Without the Python Command
Multiprocessing: Use Only the Physical Cores
Ignore Case in Glob() on Linux
Move and Zoom a Tkinter Canvas with Mouse
Opening a Python Thread in a New Console Window
How Does Collections.Defaultdict Work
Python 2.7 Cx_Freeze: Importerror: No Module Named _Startup_