Skip to content

Commit 3e4e775

Browse files
authored
Merge pull request #8681 from dstansby/pylab-moves
DOC: Move text examples out of pylab_examples
2 parents 75fde88 + dac08ce commit 3e4e775

11 files changed

+43
-38
lines changed

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

+2-2
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

+2-1
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

+9-8
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
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.

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

+2-2
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

+26-23
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,45 @@
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
45-
plt.ylabel(r'\bf{phase field} $\phi$', {'color': 'b',
46-
'fontsize': 20})
49+
plt.ylabel(r'\bf{phase field} $\phi$', {'color': 'b', 'fontsize': 20})
4750
plt.yticks((0, 0.5, 1), ('0', '.5', '1'), color='k', size=20)
4851

4952
# Right Y-axis labels
5053
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)
54+
horizontalalignment='left',
55+
verticalalignment='center',
56+
rotation=90,
57+
clip_on=False)
5558
plt.text(1.01, -0.02, "-1", {'color': 'k', 'fontsize': 20})
5659
plt.text(1.01, 0.98, "1", {'color': 'k', 'fontsize': 20})
5760
plt.text(1.01, 0.48, "0", {'color': 'k', 'fontsize': 20})
5861

5962
# level set equations
6063
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})
64+
r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t}'
65+
r'+ U|\nabla \phi| = 0$',
66+
{'color': 'g', 'fontsize': 20})
6467

6568
# phase field equations
6669
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})
70+
r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline '
71+
r'$ \frac{ \partial \phi } { \partial t } = -M_{ \phi } '
72+
r'\frac{ \delta \mathcal{F} } { \delta \phi }$',
73+
{'color': 'b', 'fontsize': 20})
7174

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

tutorials/01_introductory/sample_plots.py

+2-2
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)