У меня есть класс, который я использую для построения графиков и сохранения их в файл.Вот его упрощенная версия:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class Test():
def __init__(self, x, y, filename):
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot(x, y, 'D', color='red')
ax.set_xbound(-5,5)
ax.set_ybound(-5,5)
plt.savefig('%s.png' % filename)
test1 = Test(1,2, 'test1')
test2 = Test(2,4, 'test2')
Вот результаты:
test1