Вот код, который работает:
< pre class="lang-py Prettyprint-override">
Код: Выделить всё
import matplotlib.pyplot as plt
# Set the LaTeX formula
formula = r"$L_0(x)=x \quad ; \quad L_n(x)=L_{n-1}^2-2 \quad \forall n \geq 1$"
# Create a figure and an axis to display the formula
fig, ax = plt.subplots(figsize=(6, 1))
ax.text(0.5, 0.5, formula, fontsize=20, ha='center', va='center')
ax.axis('off') # Remove axes to show only the formula
# Save as SVG
plt.savefig("formula.svg", format="svg")
plt.show()
Код: Выделить всё
import matplotlib.pyplot as plt
# Set the LaTeX formula
formula = r"$L_n= \begin{cases}4 & \text { if } n=0 \\ L_{n-1}^2-2 & \text { otherwise }\end{cases}$"
# Create a figure and an axis to display the formula
fig, ax = plt.subplots(figsize=(6, 1))
ax.text(0.5, 0.5, formula, fontsize=20, ha='center', va='center')
ax.axis('off') # Remove axes to show only the formula
# Save as SVG
plt.savefig("formula.svg", format="svg")
plt.show()
Код: Выделить всё
ValueError:
L_n= \begin{cases}4 & \text { if } n=0 \\ L_{n-1}^2-2 & \text { otherwise }\end{cases}
^
ParseFatalException: Unknown symbol: \begin, found '\' (at char 5), (line:1, col:6)
Спасибо за помощь!
Подробнее здесь: https://stackoverflow.com/questions/791 ... matplotlib
Мобильная версия