help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python Matplotlib with MPLBACKEND TkAgg


From: Jake
Subject: Python Matplotlib with MPLBACKEND TkAgg
Date: Fri, 19 Apr 2024 00:58:58 +0000

Hi

I'm not sure how to get Python's Matplotlib to plot using the MPLBACKEND
TkAgg without hardcoding it in the python script.

I can get the WebAgg backend to work by setting the MPLBACKEND env var:

#+begin_src sh

  guix shell python python-matplotlib python-tornado -- bash -c
'MPLBACKEND=WebAgg python3 -c "import matplotlib;
print(matplotlib.get_backend()); import matplotlib.pyplot as plt;
plt.plot([1],[2]); plt.show()"'

#+end_src

#+RESULTS:
: WebAgg
: Press Ctrl+C to stop WebAgg server

This approach doesn't seem to work for the TkAgg backend:

#+begin_src sh

  guix shell python python-matplotlib -- bash -c 'MPLBACKEND=TkAgg python3
-c "import matplotlib; print(matplotlib.get_backend()); import
matplotlib.pyplot as plt; plt.plot([1],[2]); plt.show()"'

#+end_src

#+RESULTS:
: TkAgg
: <string>:1: UserWarning: FigureCanvasAgg is non-interactive, and thus
cannot be shown

The TkAgg backend does work if I hardcode it in the Python script using
`matplotlib.use()`, but this approach is undesirable:

#+begin_src sh

  guix shell python python-matplotlib -- python3 -c "import matplotlib;
matplotlib.use('TkAgg'); print(matplotlib.get_backend()); import
matplotlib.pyplot as plt; plt.plot([1],[2]); plt.show()"

#+end_src

#+RESULTS:
: TkAgg

Thanks in advance!

Jake


reply via email to

[Prev in Thread] Current Thread [Next in Thread]