fixed a bug with wrong LaTeX input

This commit is contained in:
Daniel Knuettel 2018-02-03 18:31:47 +01:00
parent 249e64bc72
commit 6095292560
1 changed files with 20 additions and 7 deletions

View File

@ -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