Skip to content

Move text examples out of pylab_examples #8681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
tab = plt.table(cellText=chars,
rowLabels=labelr,
colLabels=labelc,
rowColours=[lightgrn]*16,
colColours=[lightgrn]*16,
rowColours=[lightgrn] * 16,
colColours=[lightgrn] * 16,
cellColours=colors,
cellLoc='center',
loc='upper left')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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

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

show()
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@

def doall():
# Colors used in mpl online documentation.
mpl_blue_rvb = (191./255., 209./256., 212./255.)
mpl_orange_rvb = (202/255., 121/256., 0./255.)
mpl_grey_rvb = (51./255., 51./255., 51./255.)
mpl_blue_rvb = (191. / 255., 209. / 256., 212. / 255.)
mpl_orange_rvb = (202. / 255., 121. / 256., 0. / 255.)
mpl_grey_rvb = (51. / 255., 51. / 255., 51. / 255.)

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

# Plotting features demonstration formulae
for i_line in range(1, n_lines):
baseline = 1. - (i_line)*line_axesfrac
baseline_next = baseline - line_axesfrac*1.
baseline = 1 - (i_line) * line_axesfrac
baseline_next = baseline - line_axesfrac
title = mathtext_titles[i_line] + ":"
fill_color = ['white', mpl_blue_rvb][i_line % 2]
plt.fill_between([0., 1.], [baseline, baseline],
[baseline_next, baseline_next],
color=fill_color, alpha=0.5)
plt.annotate(title,
xy=(0.07, baseline - 0.3*line_axesfrac),
xy=(0.07, baseline - 0.3 * line_axesfrac),
xycoords='data', color=mpl_grey_rvb, weight='bold')
demo = mathext_demos[i_line]
plt.annotate(demo,
xy=(0.05, baseline - 0.75*line_axesfrac),
xy=(0.05, baseline - 0.75 * line_axesfrac),
xycoords='data', color=mpl_grey_rvb,
fontsize=16)

Expand All @@ -106,6 +106,7 @@ def doall():
print(i, s)
plt.show()


if '--latex' in sys.argv:
# Run: python mathtext_examples.py --latex
# Need amsmath and amssymb packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def draw(self, renderer):
plt.rcParams["text.usetex"] = usetex
plt.rcParams["text.latex.preview"] = preview


subplot = maxes.subplot_class_factory(Axes)


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

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


fig = plt.figure(figsize=(2.*3, 6.5))
fig = plt.figure(figsize=(2 * 3, 6.5))

for i, usetex, preview in [[0, False, False],
[1, True, False],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
N = 500
delta = 0.6
X = np.linspace(-1, 1, N)
plt.plot(X, (1 - np.tanh(4.*X/delta))/2, # phase field tanh profiles
X, (X + 1)/2, # level set distance function
X, (1.4 + np.tanh(4.*X/delta))/4, # composition profile
X, X < 0, 'k--', # sharp interface
)
plt.plot(X, (1 - np.tanh(4 * X / delta)) / 2, # phase field tanh profiles
X, (X + 1) / 2, # level set distance function
X, (1.4 + np.tanh(4 * X / delta)) / 4, # composition profile
X, X < 0, 'k--') # sharp interface

# legend
plt.legend(('phase field', 'level set', 'composition', 'sharp interface'), shadow=True, loc=(0.01, 0.55))
plt.legend(('phase field', 'level set', 'composition', 'sharp interface'),
shadow=True, loc=(0.01, 0.55))

ltext = plt.gca().get_legend().get_texts()
plt.setp(ltext[0], fontsize=20)
Expand All @@ -32,42 +32,45 @@
height = 0.1
offset = 0.02
plt.plot((-delta / 2., delta / 2), (height, height), 'k', linewidth=2)
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height - offset), 'k', linewidth=2)
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset), 'k', linewidth=2)
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset), 'k', linewidth=2)
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset), 'k', linewidth=2)
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height - offset),
'k', linewidth=2)
plt.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset),
'k', linewidth=2)
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset),
'k', linewidth=2)
plt.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset),
'k', linewidth=2)
plt.text(-0.06, height - 0.06, r'$\delta$', {'color': 'k', 'fontsize': 24})

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

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

# Right Y-axis labels
plt.text(1.05, 0.5, r"\bf{level set} $\phi$", {'color': 'g', 'fontsize': 20},
horizontalalignment='left',
verticalalignment='center',
rotation=90,
clip_on=False)
horizontalalignment='left',
verticalalignment='center',
rotation=90,
clip_on=False)
plt.text(1.01, -0.02, "-1", {'color': 'k', 'fontsize': 20})
plt.text(1.01, 0.98, "1", {'color': 'k', 'fontsize': 20})
plt.text(1.01, 0.48, "0", {'color': 'k', 'fontsize': 20})

# level set equations
plt.text(0.1, 0.85,
r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t}'
r'+ U|\nabla \phi| = 0$',
{'color': 'g', 'fontsize': 20})
r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t}'
r'+ U|\nabla \phi| = 0$',
{'color': 'g', 'fontsize': 20})

# phase field equations
plt.text(0.2, 0.15,
r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline '
r'$ \frac{ \partial \phi } { \partial t } = -M_{ \phi } '
r'\frac{ \delta \mathcal{F} } { \delta \phi }$',
{'color': 'b', 'fontsize': 20})
r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline '
r'$ \frac{ \partial \phi } { \partial t } = -M_{ \phi } '
r'\frac{ \delta \mathcal{F} } { \delta \phi }$',
{'color': 'b', 'fontsize': 20})

# these went wrong in pdf in a previous version
plt.text(-.9, .42, r'gamma: $\gamma$', {'color': 'r', 'fontsize': 20})
Expand Down
4 changes: 2 additions & 2 deletions tutorials/01_introductory/sample_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@
and the DejaVu, BaKoMa computer modern, or `STIX <http://www.stixfonts.org>`_
fonts. See the :mod:`matplotlib.mathtext` module for additional details.

.. figure:: ../../gallery/pylab_examples/images/sphx_glr_mathtext_examples_001.png
:target: ../../gallery/pylab_examples/mathtext_examples.html
.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_mathtext_examples_001.png
:target: ../../gallery/text_labels_and_annotations/mathtext_examples.html
:align: center
:scale: 50

Expand Down