Pgf序言

  1. import matplotlib as mpl
  2. mpl.use("pgf")
  3. import matplotlib.pyplot as plt
  4. plt.rcParams.update({
  5. "font.family": "serif", # use serif/main font for text elements
  6. "text.usetex": True, # use inline math for ticks
  7. "pgf.rcfonts": False, # don't setup fonts from rc parameters
  8. "pgf.preamble": [
  9. "\\usepackage{units}", # load additional packages
  10. "\\usepackage{metalogo}",
  11. "\\usepackage{unicode-math}", # unicode math setup
  12. r"\setmathfont{xits-math.otf}",
  13. r"\setmainfont{DejaVu Serif}", # serif font via preamble
  14. ]
  15. })
  16. plt.figure(figsize=(4.5, 2.5))
  17. plt.plot(range(5))
  18. plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
  19. plt.ylabel("\\XeLaTeX")
  20. plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
  21. plt.tight_layout(.5)
  22. plt.savefig("pgf_preamble.pdf")
  23. plt.savefig("pgf_preamble.png")

下载这个示例