-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
PEP8 moved text examples Fix tutorial links Fix up rebase
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
@@ -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 * 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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) | ||
|
||
|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
""" | ||
================================= | ||
Rendering math equation using TeX | ||
================================= | ||
======== | ||
Tex Demo | ||
======== | ||
|
||
You can use TeX to render all of your matplotlib text if the rc | ||
parameter text.usetex is set. This works currently on the agg and ps | ||
backends, and requires that you have tex and the other dependencies | ||
described at http://matplotlib.org/users/usetex.html | ||
properly installed on your system. The first time you run a script | ||
you will see a lot of output from tex and associated tools. The next | ||
time, the run may be silent, as a lot of the information is cached. | ||
|
||
Notice how the the label for the y axis is provided using unicode! | ||
time, the run may be silent, as a lot of the information is cached in | ||
~/.tex.cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be here; I think you may have resolved conflicts in the opposite direction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just put back in the master copy of tex_demo.py, which I think is correct. |
||
|
||
""" | ||
from __future__ import unicode_literals | ||
import numpy as np | ||
import matplotlib | ||
matplotlib.rcParams['text.usetex'] = True | ||
matplotlib.rcParams['text.latex.unicode'] = True | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
plt.rc('text', usetex=True) | ||
plt.rc('font', family='serif') | ||
plt.figure(1, figsize=(6, 4)) | ||
ax = plt.axes([0.1, 0.1, 0.8, 0.7]) | ||
t = np.linspace(0.0, 1.0, 100) | ||
s = np.cos(4 * np.pi * t) + 2 | ||
plt.plot(t, s) | ||
|
||
fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True) | ||
ax.plot(t, s) | ||
|
||
ax.set_xlabel(r'\textbf{time (s)}') | ||
ax.set_ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16) | ||
ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty' | ||
r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r') | ||
plt.xlabel(r'\textbf{time (s)}') | ||
plt.ylabel(r'\textit{voltage (mV)}', fontsize=16) | ||
plt.title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty" | ||
r"\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r') | ||
plt.grid(True) | ||
plt.savefig('tex_demo') | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -32,42 +32,46 @@ | |
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}) | ||
'fontsize': 20}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well break before the |
||
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}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs
from __future__ import division
for this to work on Python 2.