|
|
|||||||||||||||||||||||||||||
|
matplotlib pyplots_Examples 31_tex_demo. |
H.Kamifuji . |
"""
Demo of TeX rendering.
You can use TeX to render all of your matplotlib text if the rc
parameter text.usetex is set. This works currently on the agg and ps
backends, and requires that you have tex and the other dependencies
described at http://matplotlib.org/users/usetex.html
properly installed on your system. The first time you run a script
you will see a lot of output from tex and associated tools. The next
time, the run may be silent, as a lot of the information is cached in
~/.tex.cache
"""
import numpy as np
import matplotlib.pyplot as plt
# Example data
t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.plot(t, s)
plt.xlabel(r'\textbf{time} (s)')
plt.ylabel(r'\textit{voltage} (mV)',fontsize=16)
plt.title(r"\TeX\ is Number "
r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
fontsize=16, color='gray')
# Make room for the ridiculously large title.
plt.subplots_adjust(top=0.8)
plt.savefig('tex_demo')
plt.show()
|
|
当方の環境では、動作しない。 Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 tex_demo.txt matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。 tex_demo_3116_371.txt Python 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 tex_demo_3120_381.txt 当方の環境では、LaTeX をインストールしてないので、確認できない。 |
| pyplots_Examples code: tex_demo.py |
|