用python打印乳胶配方

2024-05-17 05:28:08 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python中显示简单的乳胶公式? 也许努比是正确的选择?

编辑:

我有python代码,比如:

a = '\frac{a}{b}'

并希望在图形输出中打印(如matplotlib)。


Tags: 代码图形编辑matplotlib乳胶公式frac
3条回答

Matplotlib已经可以通过在~/.matplotlib/matplotlibrc中设置text.usetex: True来执行TeX。然后,您可以在所有显示的字符串中使用TeX,例如

ylabel(r"Temperature (K) [fixed $\beta=2$]")

(确保使用$作为正常的内联TeX!)。字符串前面的r表示不进行任何替换;否则您必须逃过前面提到的斜杠。

更多信息请访问matplotlib站点。

不带刻度:

a = r'\frac{a}{b}'
ax = plt.axes([0,0,0.1,0.2]) #left,bottom,width,height
ax.set_xticks([])
ax.set_yticks([])
plt.text(0.3,0.4,'$%s$' %a,size=40)

正如Andrew所建议的那样,很少使用matplotlib。

import matplotlib.pyplot as plt
a = '\\frac{a}{b}'  #notice escaped slash
plt.plot()
plt.text(0.5, 0.5,'$%s$'%a)
plt.show()

相关问题 更多 >