The default backend is chosen based on the content of the $DISPLAY
variable *and* a successfull call to libX11, loaded via dlopen().
The test fails because dlopen looks in /usr/lib and /lib, so matplotlib
falls back to a headless backend.
To reproduce try running:
$ nix-shell -I nixpkgs=$PWD -p \
'python3.withPackages (p: [ p.matplotlib ])' --run python
>>> import matplotlib.pyplot as plt
>>> assert plt.get_backend() == "TkAgg"