|
1 | 1 | """ |
2 | | -=========== |
3 | | -Pyplot Text |
4 | | -=========== |
| 2 | +============================== |
| 3 | +Text and mathtext using pyplot |
| 4 | +============================== |
5 | 5 |
|
6 | | -""" |
7 | | -import numpy as np |
8 | | -import matplotlib.pyplot as plt |
| 6 | +Set the special text objects `~.pyplot.title`, `~.pyplot.xlabel`, and |
| 7 | +`~.pyplot.ylabel` through the dedicated pyplot functions. Additional text |
| 8 | +objects can be placed in the axes using `~.pyplot.text`. |
9 | 9 |
|
10 | | -# Fixing random state for reproducibility |
11 | | -np.random.seed(19680801) |
| 10 | +You can use TeX-like mathematical typesetting in all texts; see also |
| 11 | +:doc:`/tutorials/text/mathtext`. |
12 | 12 |
|
13 | | -mu, sigma = 100, 15 |
14 | | -x = mu + sigma * np.random.randn(10000) |
| 13 | +.. redirect-from:: /gallery/pyplots/pyplot_mathtext |
| 14 | +""" |
15 | 15 |
|
16 | | -# the histogram of the data |
17 | | -n, bins, patches = plt.hist(x, 50, density=True, facecolor='g', alpha=0.75) |
| 16 | +import numpy as np |
| 17 | +import matplotlib.pyplot as plt |
18 | 18 |
|
| 19 | +t = np.arange(0.0, 2.0, 0.01) |
| 20 | +s = np.sin(2*np.pi*t) |
19 | 21 |
|
20 | | -plt.xlabel('Smarts') |
21 | | -plt.ylabel('Probability') |
22 | | -plt.title('Histogram of IQ') |
23 | | -plt.text(60, .025, r'$\mu=100,\ \sigma=15$') |
24 | | -plt.xlim(40, 160) |
25 | | -plt.ylim(0, 0.03) |
26 | | -plt.grid(True) |
| 22 | +plt.plot(t, s) |
| 23 | +plt.text(0, -1, r'Hello, world!', fontsize=15) |
| 24 | +plt.title(r'$\mathcal{A}\sin(\omega t)$', fontsize=20) |
| 25 | +plt.xlabel('Time [s]') |
| 26 | +plt.ylabel('Voltage [mV]') |
27 | 27 | plt.show() |
28 | 28 |
|
29 | 29 | ############################################################################# |
|
0 commit comments