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

Skip to content

Commit a3fcaa3

Browse files
committed
Add kwarg 'markup' for all text that allows the user to choose either
'plain' or 'tex' markup. A default may also be provided in the rcParam 'text.markup'. Minor bugfix to mathtext.py svn path=/trunk/matplotlib/; revision=3664
1 parent 09d2e64 commit a3fcaa3

16 files changed

Lines changed: 63 additions & 33 deletions

examples/accented_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
plot(range(10))
1515

16-
title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20)
16+
title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20, markup="tex")
1717
# shorthand is also supported and curly's are optional
18-
xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20)
18+
xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20, markup="tex")
1919

2020

2121
show()

examples/arrow_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
5252
min_text_size = size
5353
label_text_size = size*2.5
5454
text_params={'ha':'center', 'va':'center', 'family':'sans-serif',\
55-
'fontweight':'bold'}
55+
'fontweight':'bold', 'markup': 'tex'}
5656
r2 = sqrt(2)
5757

5858
deltas = {\
@@ -211,7 +211,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
211211
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])
212212

213213
text(x, y, label, size=label_text_size, ha='center', va='center', \
214-
color=labelcolor or fc)
214+
color=labelcolor or fc, markup='tex')
215215

216216
for p in positions.keys():
217217
draw_arrow(p)

examples/dannys_example.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,32 @@
2929
pylab.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset), 'k', linewidth = 2)
3030
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset), 'k', linewidth = 2)
3131
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset), 'k', linewidth = 2)
32-
pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24})
32+
pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24}, markup = 'tex')
3333

3434
## X-axis label
3535
pylab.xticks((-1, 0, 1), ('-1', '0', '1'), color = 'k', size = 20)
3636

3737
## Left Y-axis labels
3838
pylab.ylabel(r'\bf{phase field} $\phi$', {'color' : 'b',
39-
'fontsize' : 20 })
39+
'fontsize' : 20 }, markup='tex')
4040
pylab.yticks((0, 0.5, 1), ('0', '.5', '1'), color = 'k', size = 20)
4141

4242
## Right Y-axis labels
4343
pylab.text(1.05, 0.5, r"\bf{level set} $\phi$", {'color' : 'g', 'fontsize' : 20},
4444
horizontalalignment = 'left',
4545
verticalalignment = 'center',
4646
rotation = 90,
47-
clip_on = False)
47+
clip_on = False,
48+
markup = 'tex')
4849
pylab.text(1.01, -0.02, "-1", {'color' : 'k', 'fontsize' : 20})
4950
pylab.text(1.01, 0.98, "1", {'color' : 'k', 'fontsize' : 20})
5051
pylab.text(1.01, 0.48, "0", {'color' : 'k', 'fontsize' : 20})
5152

5253
## level set equations
53-
pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20})
54+
pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20}, markup='tex')
5455

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

5859
pylab.savefig('pfm-lsm.png')
5960
pylab.show()

examples/histogram_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
xlabel('Smarts')
1717
ylabel('Probability')
18-
title(r'$\rm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
18+
title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$', markup='tex')
1919
axis([40, 160, 0, 0.03])
2020
grid(True)
2121

examples/histogram_demo_canvasagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
ax.set_xlabel('Smarts')
3535
ax.set_ylabel('Probability')
36-
ax.set_title(r'$\rm{Histogram of IQ: }\mu=100, \sigma=15$')
36+
ax.set_title(r'$\mathrm{Histogram of IQ: }\mu=100, \sigma=15$', markup='tex')
3737

3838
ax.set_xlim( (40, 160))
3939
ax.set_ylim( (0, 0.03))

examples/integral_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def func(x):
2222
ax.add_patch(poly)
2323

2424
text(0.5 * (a + b), 30,
25-
r"$\int_a^b f(x)\rm{d}x$", horizontalalignment='center',
26-
fontsize=20)
25+
r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
26+
fontsize=20, markup='tex')
2727

2828
axis([0,10, 0, 180])
2929
figtext(0.9, 0.05, 'x')

examples/legend_auto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def fig_6():
5151
def fig_7():
5252
figure(7)
5353
xx = x - (N/2.0)
54-
plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$')
55-
plot(xx, 25*xx, 'go', label='$y=25x$')
56-
plot(xx, -25*xx, 'mo', label='$y=-25x$')
54+
plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$', markup='tex')
55+
plot(xx, 25*xx, 'go', label='$y=25x$', markup='tex')
56+
plot(xx, -25*xx, 'mo', label='$y=-25x$', markup='tex')
5757
legend()
5858

5959
def fig_8():

examples/mathtext_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20)
1818
tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$'
1919

20-
ax.text(1, 1.6, tex, fontsize=20, va='bottom')
20+
ax.text(1, 1.6, tex, fontsize=20, va='bottom', markup="tex")
2121

2222
#title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
2323
fig.savefig('mathtext_demo')

examples/mathtext_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
x = arange(0.0, 3.0, 0.1)
6363

6464
grid(True)
65-
text(1, 1.6, s, fontsize=20)
65+
text(1, 1.6, s, fontsize=20, markup="tex")
6666

6767
savefig('mathtext_example%02d' % i)
6868
figure()

examples/scatter_demo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
close = 0.003*intc.close[:-2]/0.003*intc.open[:-2]
1212
p = scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.75)
1313

14-
xlabel(r'$\Delta_i$', size='x-large')
15-
ylabel(r'$\Delta_{i+1}$', size='x-large')
14+
xlabel(r'$\Delta_i$', size='x-large', markup='tex')
15+
ylabel(r'$\Delta_{i+1}$', size='x-large', markup='tex')
1616
title(r'Volume and percent change')
1717
grid(True)
1818
#savefig('scatter_demo2')

0 commit comments

Comments
 (0)