diff --git a/mathbot/rendering.py b/mathbot/rendering.py index a001d78..1c721a0 100644 --- a/mathbot/rendering.py +++ b/mathbot/rendering.py @@ -20,21 +20,34 @@ from io import BytesIO import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt +import importlib def get_png(tex): + importlib.reload(plt) buf = BytesIO() - plt.text(0, 0.6, r"$%s$" % tex, fontsize = 50) - fig = plt.gca() - fig.axes.get_xaxis().set_visible(False) - fig.axes.get_yaxis().set_visible(False) + exc = None - plt.savefig(buf) + try: + plt.subplot() - buf.seek(0) + plt.text(0, 0.6, r"$%s$" % tex, fontsize = 50) + fig = plt.gca() + fig.axes.get_xaxis().set_visible(False) + fig.axes.get_yaxis().set_visible(False) - plt.clf() + plt.savefig(buf) + + buf.seek(0) + + except Exception as e: + exc = e + finally: + plt.clf() + + if(exc): + raise exc return buf