I am working with flask in a virtual environment. I was able to install matplotlib with pip, and I can import matplotlib in a Python session. However, when I im
If you do not want to set a .matplotib/matplotlibrc configuration file, you can circumvent this issue by setting the 'Agg' backend at runtime right after importing matplotlib and before importing matplotlib.pyplot:
In [1]: import matplotlib
In [2]: matplotlib.use('Agg')
In [3]: import matplotlib.pyplot as plt
In [4]: fig, ax = plt.subplots(1, 1)
In [5]: import numpy as np
In [6]: x = np.linspace(-1., 1.)
In [7]: y = np.sin(x)
In [8]: ax.plot(x, y)
Out[8]: []
In [9=]: fig.savefig('myplot.png')