Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

Hi cdb experts.

I am in the

  • Jupyter notebook with Cadabra2 kernel
  • Ubuntu 22.04

When trying to use matplotlib, I get the error

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

and when I specifically set the backend to TkAgg I get

UserWarning: Matplotlib is currently using TkAgg, which is a non-GUI backend, so cannot show the figure

even though Tk is a GUI backend.

I have set the pythonpath to

PYTHONPATH=/usr/lib/python3.10/:/usr/lib/python3.10/dist-packages:/usr/lib/python3.10/tkinter/

and I do have both matplotlib and tkinter ("python3-tk") installed. What am I doing wrong, please?

Thank you!

P.S. As an example, the following code produces said error:

import matplotlib.pyplot as plt
from cdb.core.component import *

{i,j,k,l,m,n}::Indices(rotation, values={1,2,3}).
\epsilon{#}::EpsilonTensor.
Ki := (K_{i})_{m n} = \epsilon_{i m n}.
evaluate(Ki, rhsonly=True);

fig = plt.figure()

with plt.rc_context({'backend':'tkagg'}):
    for i in range(3):
        for j in range(3):
            val = get_component(Ki, $1, 0, 0$)
            plt.text(i,j,str(val), va='center',ha='center')

    plt.show()

Many thanks!

in General questions by (2.0k points)
edited by

1 Answer

+2 votes
 
Best answer

Cadabra doesn't use plt.show(). Just display the fig object with

fig;

or

display(fig)
by (82.5k points)
selected by
...