Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default GUI backend for Matplotlib?

I have made the following script, let's call it test-matplotlib-printbackend.py:

#!/usr/bin/env python

import matplotlib as mpl
import matplotlib.pyplot as plt

xx = range(100)
yy = [i*2+5 for i in xx]

fig, ax = plt.subplots()
ax.plot(xx, yy)

print("Matplotlib plt backend: {}".format(plt.get_backend()))

plt.show()

For Python3 under MINGW64 on Windows 10, as well as Python3 under Anaconda on Windows 10, I get the printout:

Matplotlib plt backend: Qt5Agg

However, for Python3 on Rasbian (Raspberry Pi's Debian OS), I get the printout:

Matplotlib plt backend: TkAgg

This kind of puzzles me, because I sort of expected TkAgg would be the default GUI backend for matplotlib on all platforms !?

So, I just wanted to know - is the default GUI backend for Matplotlib for different platforms documented anywhere?

like image 732
sdbbs Avatar asked Mar 09 '26 23:03

sdbbs


1 Answers

The backend selection logic is not very transparent and not well documented.

In modern matplotlib there is no "default backend", i.e. the rcParams['backend'] is set to a "sentinel".
Upon importing matplotlib the first working backend from a candidate list ["macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", "wxagg"] is chosen.

In order to avoid this automatic selection, you can set the backend manually via the rcParams['backend'] parameter or the MPLBACKEND environment variable. That part is documented

like image 127
ImportanceOfBeingErnest Avatar answered Mar 12 '26 13:03

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!