Open bluthej opened 1 month ago
This is a big issue for me as well. Any help would be appreciated.
For people coming here and needing immediate help, setting your backend as described here may solve your problem: https://matplotlib.org/stable/users/explain/figure/backends.html
What operating system and Python version do you use, and do you set and custom matplotlib settings? For me, with Ubuntu 24.04 and cpython-3.12.1-linux-x86_64-gnu
:
pyproject.toml
[project]
name = "mpl-basic"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"matplotlib>=3.9.2",
]
main.py
import matplotlib.pyplot as plt
if __name__ == '__main__':
print(plt.get_backend())
plt.plot([0, 1], [0, 1])
plt.savefig("hello.png")
With uv run main.py
, I get agg
as backend and a hello.png
.
Running into this too. savefig
works fine with the standalone builds; the problem is when trying to bring up an interactive window.
For example, when running:
from matplotlib import pyplot
pyplot.plot([0, 1], [0, 1])
pyplot.show()
gives the warning on the call to pyplot.show()
(and nothing else of interest happens besides the program terminating)
UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
I'm running with cpython-3.11.9-linux-x86_64-gnu on WSL (ubuntu 22.04) right now.
edit: my current workaround is to have PyQt6
installed in whichever environment I'm working, as matplotlib will then pick that up as the default interactive backend without any further intervention (I haven't set additional environment variables or call matplotlib.use
explicitly).
I am on a mac and was running matplotlib 3.9.1 and 3.9.0.
savefig('foo.pdf')
was causing issues.
Not sure why it was trying to use tk when nothing about it was interactive.
@konstin as I said in the issue, the problems I'm having are with the interactive backend, the static backend indeed works just fine out of the box (just like what @tpgillam said).
From the matplot lib issue tracker (comment), apparently:
I am on Linux and it seems like tkagg is the default interactive backend (not sure about other platforms):
Since uv relies on python-build-standalone for managed installs, this has the unfortunate consequence that I have to use my system Python whenever I need to plot something in interactive mode.
This is related to this matplotlib issue and this python-build-standalone issue, at which point things were even worse because people couldn't even
import matplotlib
successfully!It sounds like python-build-standalone and tkagg will not be compatible anytime soon. I don't necessarily mind, but in any case I think it would be nice if we could either:
Hardly a day goes by that I don't need to plot something with matplotlib and I assume I am not alone, so this should benefit a lot of people!