4

I need to use TkAgg backend in matplotlib to plot on my machine (A) while calculating via ssh in another machine (B).

Following other questions like this, I do:

import matplotlib
matplotlib.use('TkAgg')
matplotlib.get_backend() # prints: 'TkAgg'

import matplotlib.pyplot as plt
matplotlib.get_backend() # prints: 'agg'

# Plotting...
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

plt.plot(t, s)
plt.show()

But gives the error:

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

It seems that every time I import matplotlib.pyplot it switches back to the default backend!

What do I need to do?

Francesco Pegoraro
  • 778
  • 13
  • 33

0 Answers0