数学文本图像作为numpy数组

从LaTeX字符串制作图像。

  1. import matplotlib.mathtext as mathtext
  2. import matplotlib.pyplot as plt
  3. import matplotlib
  4. matplotlib.rc('image', origin='upper')
  5. parser = mathtext.MathTextParser("Bitmap")
  6. parser.to_png('test2.png',
  7. r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} '
  8. r'y\right)\right]$', color='green', fontsize=14, dpi=100)
  9. rgba1, depth1 = parser.to_rgba(
  10. r'IQ: $\sigma_i=15$', color='blue', fontsize=20, dpi=200)
  11. rgba2, depth2 = parser.to_rgba(
  12. r'some other string', color='red', fontsize=20, dpi=200)
  13. fig = plt.figure()
  14. fig.figimage(rgba1, 100, 100)
  15. fig.figimage(rgba2, 100, 300)
  16. plt.show()

数学文本图像作为numpy数组

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.mathtext
  3. matplotlib.mathtext.MathTextParser
  4. matplotlib.mathtext.MathTextParser.to_png
  5. matplotlib.mathtext.MathTextParser.to_rgba
  6. matplotlib.figure.Figure.figimage

下载这个示例