Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2e2aa0

Browse files
committed
Move text examples out of pylab_examples
PEP8 moved text examples Fix tutorial links Fix up rebase
1 parent cc2c508 commit f2e2aa0

File tree

12 files changed

+59
-54
lines changed

12 files changed

+59
-54
lines changed

examples/pylab_examples/font_table_ttf_sgskip.py renamed to examples/text_labels_and_annotations/font_table_ttf_sgskip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
tab = plt.table(cellText=chars,
5656
rowLabels=labelr,
5757
colLabels=labelc,
58-
rowColours=[lightgrn]*16,
59-
colColours=[lightgrn]*16,
58+
rowColours=[lightgrn] * 16,
59+
colColours=[lightgrn] * 16,
6060
cellColours=colors,
6161
cellLoc='center',
6262
loc='upper left')

examples/pylab_examples/mathtext_demo.py renamed to examples/text_labels_and_annotations/mathtext_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
ax.legend([r"$\sqrt{x^2}$"])
2727

28-
ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
28+
ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} '
29+
r'\Delta_{i+1}^j$', fontsize=20)
2930

3031
show()

examples/pylab_examples/mathtext_examples.py renamed to examples/text_labels_and_annotations/mathtext_examples.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959

6060
def doall():
6161
# Colors used in mpl online documentation.
62-
mpl_blue_rvb = (191./255., 209./256., 212./255.)
63-
mpl_orange_rvb = (202/255., 121/256., 0./255.)
64-
mpl_grey_rvb = (51./255., 51./255., 51./255.)
62+
mpl_blue_rvb = (191 / 255, 209 / 256, 212 / 255)
63+
mpl_orange_rvb = (202 / 255, 121 / 256, 0 / 255)
64+
mpl_grey_rvb = (51 / 255, 51 / 255, 51 / 255)
6565

6666
# Creating figure and axis.
6767
plt.figure(figsize=(6, 7))
@@ -79,25 +79,25 @@ def doall():
7979
# Plotting header demonstration formula
8080
full_demo = mathext_demos[0]
8181
plt.annotate(full_demo,
82-
xy=(0.5, 1. - 0.59*line_axesfrac),
82+
xy=(0.5, 1. - 0.59 * line_axesfrac),
8383
xycoords='data', color=mpl_orange_rvb, ha='center',
8484
fontsize=20)
8585

8686
# Plotting features demonstration formulae
8787
for i_line in range(1, n_lines):
88-
baseline = 1. - (i_line)*line_axesfrac
89-
baseline_next = baseline - line_axesfrac*1.
88+
baseline = 1 - (i_line) * line_axesfrac
89+
baseline_next = baseline - line_axesfrac * 1
9090
title = mathtext_titles[i_line] + ":"
9191
fill_color = ['white', mpl_blue_rvb][i_line % 2]
9292
plt.fill_between([0., 1.], [baseline, baseline],
9393
[baseline_next, baseline_next],
9494
color=fill_color, alpha=0.5)
9595
plt.annotate(title,
96-
xy=(0.07, baseline - 0.3*line_axesfrac),
96+
xy=(0.07, baseline - 0.3 * line_axesfrac),
9797
xycoords='data', color=mpl_grey_rvb, weight='bold')
9898
demo = mathext_demos[i_line]
9999
plt.annotate(demo,
100-
xy=(0.05, baseline - 0.75*line_axesfrac),
100+
xy=(0.05, baseline - 0.75 * line_axesfrac),
101101
xycoords='data', color=mpl_grey_rvb,
102102
fontsize=16)
103103

@@ -106,6 +106,7 @@ def doall():
106106
print(i, s)
107107
plt.show()
108108

109+
109110
if '--latex' in sys.argv:
110111
# Run: python mathtext_examples.py --latex
111112
# Need amsmath and amssymb packages.
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
"""
2-
=================================
3-
Rendering math equation using TeX
4-
=================================
2+
========
3+
Tex Demo
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.
13-
14-
Notice how the the label for the y axis is provided using unicode!
12+
time, the run may be silent, as a lot of the information is cached in
13+
~/.tex.cache
1514
1615
"""
17-
from __future__ import unicode_literals
1816
import numpy as np
19-
import matplotlib
20-
matplotlib.rcParams['text.usetex'] = True
21-
matplotlib.rcParams['text.latex.unicode'] = True
2217
import matplotlib.pyplot as plt
2318

2419

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])
2524
t = np.linspace(0.0, 1.0, 100)
2625
s = np.cos(4 * np.pi * t) + 2
26+
plt.plot(t, s)
2727

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')
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')
3534
plt.show()

examples/pylab_examples/usetex_baseline_test.py renamed to examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def draw(self, renderer):
3737
plt.rcParams["text.usetex"] = usetex
3838
plt.rcParams["text.latex.preview"] = preview
3939

40+
4041
subplot = maxes.subplot_class_factory(Axes)
4142

4243

@@ -46,7 +47,6 @@ def test_window_extent(ax, usetex, preview):
4647
ax.xaxis.set_visible(False)
4748
ax.yaxis.set_visible(False)
4849

49-
#t = ax.text(0., 0., r"mlp", va="baseline", size=150)
5050
text_kw = dict(va=va,
5151
size=50,
5252
bbox=dict(pad=0., ec="k", fc="none"))
@@ -67,7 +67,7 @@ def test_window_extent(ax, usetex, preview):
6767
ax.set_title("usetex=%s\npreview=%s" % (str(usetex), str(preview)))
6868

6969

70-
fig = plt.figure(figsize=(2.*3, 6.5))
70+
fig = plt.figure(figsize=(2 * 3, 6.5))
7171

7272
for i, usetex, preview in [[0, False, False],
7373
[1, True, False],

examples/pylab_examples/usetex_demo.py renamed to examples/text_labels_and_annotations/usetex_demo.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
N = 500
1414
delta = 0.6
1515
X = np.linspace(-1, 1, N)
16-
plt.plot(X, (1 - np.tanh(4.*X/delta))/2, # phase field tanh profiles
17-
X, (X + 1)/2, # level set distance function
18-
X, (1.4 + np.tanh(4.*X/delta))/4, # composition profile
19-
X, X < 0, 'k--', # sharp interface
20-
)
16+
plt.plot(X, (1 - np.tanh(4 * X / delta)) / 2, # phase field tanh profiles
17+
X, (X + 1) / 2, # level set distance function
18+
X, (1.4 + np.tanh(4 * X / delta)) / 4, # composition profile
19+
X, X < 0, 'k--') # sharp interface
2120

2221
# legend
23-
plt.legend(('phase field', 'level set', 'composition', 'sharp interface'), shadow=True, loc=(0.01, 0.55))
22+
plt.legend(('phase field', 'level set', 'composition', 'sharp interface'),
23+
shadow=True, loc=(0.01, 0.55))
2424

2525
ltext = plt.gca().get_legend().get_texts()
2626
plt.setp(ltext[0], fontsize=20)
@@ -32,42 +32,46 @@
3232
height = 0.1
3333
offset = 0.02
3434
plt.plot((-delta / 2., delta / 2), (height, height), 'k', linewidth=2)
35-
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height - offset), 'k', linewidth=2)
36-
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset), 'k', linewidth=2)
37-
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset), 'k', linewidth=2)
38-
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset), 'k', linewidth=2)
35+
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height - offset),
36+
'k', linewidth=2)
37+
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset),
38+
'k', linewidth=2)
39+
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset),
40+
'k', linewidth=2)
41+
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset),
42+
'k', linewidth=2)
3943
plt.text(-0.06, height - 0.06, r'$\delta$', {'color': 'k', 'fontsize': 24})
4044

4145
# X-axis label
4246
plt.xticks((-1, 0, 1), ('-1', '0', '1'), color='k', size=20)
4347

4448
# Left Y-axis labels
4549
plt.ylabel(r'\bf{phase field} $\phi$', {'color': 'b',
46-
'fontsize': 20})
50+
'fontsize': 20})
4751
plt.yticks((0, 0.5, 1), ('0', '.5', '1'), color='k', size=20)
4852

4953
# Right Y-axis labels
5054
plt.text(1.05, 0.5, r"\bf{level set} $\phi$", {'color': 'g', 'fontsize': 20},
51-
horizontalalignment='left',
52-
verticalalignment='center',
53-
rotation=90,
54-
clip_on=False)
55+
horizontalalignment='left',
56+
verticalalignment='center',
57+
rotation=90,
58+
clip_on=False)
5559
plt.text(1.01, -0.02, "-1", {'color': 'k', 'fontsize': 20})
5660
plt.text(1.01, 0.98, "1", {'color': 'k', 'fontsize': 20})
5761
plt.text(1.01, 0.48, "0", {'color': 'k', 'fontsize': 20})
5862

5963
# level set equations
6064
plt.text(0.1, 0.85,
61-
r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t}'
62-
r'+ U|\nabla \phi| = 0$',
63-
{'color': 'g', 'fontsize': 20})
65+
r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t}'
66+
r'+ U|\nabla \phi| = 0$',
67+
{'color': 'g', 'fontsize': 20})
6468

6569
# phase field equations
6670
plt.text(0.2, 0.15,
67-
r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline '
68-
r'$ \frac{ \partial \phi } { \partial t } = -M_{ \phi } '
69-
r'\frac{ \delta \mathcal{F} } { \delta \phi }$',
70-
{'color': 'b', 'fontsize': 20})
71+
r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline '
72+
r'$ \frac{ \partial \phi } { \partial t } = -M_{ \phi } '
73+
r'\frac{ \delta \mathcal{F} } { \delta \phi }$',
74+
{'color': 'b', 'fontsize': 20})
7175

7276
# these went wrong in pdf in a previous version
7377
plt.text(-.9, .42, r'gamma: $\gamma$', {'color': 'r', 'fontsize': 20})

tutorials/01_introductory/sample_plots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@
319319
and the DejaVu, BaKoMa computer modern, or `STIX <http://www.stixfonts.org>`_
320320
fonts. See the :mod:`matplotlib.mathtext` module for additional details.
321321
322-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_mathtext_examples_001.png
323-
:target: ../../gallery/pylab_examples/mathtext_examples.html
322+
.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_mathtext_examples_001.png
323+
:target: ../../gallery/text_labels_and_annotations/mathtext_examples.html
324324
:align: center
325325
:scale: 50
326326

0 commit comments

Comments
 (0)