set mpl.use("Agg") before "import matplotlib.pyplot as plt"