Skip to content

Commit 048cafd

Browse files
committed
Revert changes to text_demo
1 parent f2e2aa0 commit 048cafd

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
"""
2-
========
3-
Tex Demo
4-
========
2+
=================================
3+
Rendering math equation using TeX
4+
=================================
55
66
You can use TeX to render all of your matplotlib text if the rc
77
parameter text.usetex is set. This works currently on the agg and ps
88
backends, and requires that you have tex and the other dependencies
99
described at http://matplotlib.org/users/usetex.html
1010
properly installed on your system. The first time you run a script
1111
you will see a lot of output from tex and associated tools. The next
12-
time, the run may be silent, as a lot of the information is cached in
13-
~/.tex.cache
12+
time, the run may be silent, as a lot of the information is cached.
13+
14+
Notice how the the label for the y axis is provided using unicode!
1415
1516
"""
17+
from __future__ import unicode_literals
1618
import numpy as np
19+
import matplotlib
20+
matplotlib.rcParams['text.usetex'] = True
21+
matplotlib.rcParams['text.latex.unicode'] = True
1722
import matplotlib.pyplot as plt
1823

1924

20-
plt.rc('text', usetex=True)
21-
plt.rc('font', family='serif')
22-
plt.figure(1, figsize=(6, 4))
23-
ax = plt.axes([0.1, 0.1, 0.8, 0.7])
2425
t = np.linspace(0.0, 1.0, 100)
2526
s = np.cos(4 * np.pi * t) + 2
26-
plt.plot(t, s)
2727

28-
plt.xlabel(r'\textbf{time (s)}')
29-
plt.ylabel(r'\textit{voltage (mV)}', fontsize=16)
30-
plt.title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty"
31-
r"\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r')
32-
plt.grid(True)
33-
plt.savefig('tex_demo')
28+
fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)
29+
ax.plot(t, s)
30+
31+
ax.set_xlabel(r'\textbf{time (s)}')
32+
ax.set_ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16)
33+
ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty'
34+
r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r')
3435
plt.show()

0 commit comments

Comments
 (0)