What is a good, default backend for matplotlib
Solution 1:
Both Agg
and TkAgg
do not require any dependencies beyond Python's standard library.
I have had some issues with TkAgg
and multi-threading, so if you only need to save to files (and not plt.show()
), I would recommend using Agg
instead (just replace it where TkAgg
appears below).
Either add the following line to your ~/.config/matplotlib/matplotlibrc
:
backend: TkAgg
Or the following lines to your python file:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
Solution 2:
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,100)
y = np.sin(x)
plt.plot(x,y)
plt.show()
PyQt5 is the best backend for Matplotlib from my knowledge. It allows all the edits even after you run your program. To use it,
import matplotlib
matplotlib.use('Qt5Agg')
put this first before calling
import matplotlib.pyplot as plt
N.B. you need to install PyQt5
for installation via pip, run command
pip install PyQt5