|
From: <md...@us...> - 2007-08-02 18:37:33
|
Revision: 3664
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3664&view=rev
Author: mdboom
Date: 2007-08-02 11:37:32 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
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
Modified Paths:
--------------
trunk/matplotlib/examples/accented_text.py
trunk/matplotlib/examples/arrow_demo.py
trunk/matplotlib/examples/dannys_example.py
trunk/matplotlib/examples/histogram_demo.py
trunk/matplotlib/examples/histogram_demo_canvasagg.py
trunk/matplotlib/examples/integral_demo.py
trunk/matplotlib/examples/legend_auto.py
trunk/matplotlib/examples/mathtext_demo.py
trunk/matplotlib/examples/mathtext_examples.py
trunk/matplotlib/examples/scatter_demo2.py
trunk/matplotlib/examples/tex_demo.py
trunk/matplotlib/examples/tex_unicode_demo.py
trunk/matplotlib/lib/matplotlib/mathtext.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/lib/matplotlib/text.py
trunk/matplotlib/matplotlibrc.template
Modified: trunk/matplotlib/examples/accented_text.py
===================================================================
--- trunk/matplotlib/examples/accented_text.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/accented_text.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -13,9 +13,9 @@
plot(range(10))
-title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20)
+title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20, markup="tex")
# shorthand is also supported and curly's are optional
-xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20)
+xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20, markup="tex")
show()
Modified: trunk/matplotlib/examples/arrow_demo.py
===================================================================
--- trunk/matplotlib/examples/arrow_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/arrow_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -52,7 +52,7 @@
min_text_size = size
label_text_size = size*2.5
text_params={'ha':'center', 'va':'center', 'family':'sans-serif',\
- 'fontweight':'bold'}
+ 'fontweight':'bold', 'markup': 'tex'}
r2 = sqrt(2)
deltas = {\
@@ -211,7 +211,7 @@
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])
text(x, y, label, size=label_text_size, ha='center', va='center', \
- color=labelcolor or fc)
+ color=labelcolor or fc, markup='tex')
for p in positions.keys():
draw_arrow(p)
Modified: trunk/matplotlib/examples/dannys_example.py
===================================================================
--- trunk/matplotlib/examples/dannys_example.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/dannys_example.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -29,14 +29,14 @@
pylab.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset), 'k', linewidth = 2)
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset), 'k', linewidth = 2)
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset), 'k', linewidth = 2)
-pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24})
+pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24}, markup = 'tex')
## X-axis label
pylab.xticks((-1, 0, 1), ('-1', '0', '1'), color = 'k', size = 20)
## Left Y-axis labels
pylab.ylabel(r'\bf{phase field} $\phi$', {'color' : 'b',
- 'fontsize' : 20 })
+ 'fontsize' : 20 }, markup='tex')
pylab.yticks((0, 0.5, 1), ('0', '.5', '1'), color = 'k', size = 20)
## Right Y-axis labels
@@ -44,16 +44,17 @@
horizontalalignment = 'left',
verticalalignment = 'center',
rotation = 90,
- clip_on = False)
+ clip_on = False,
+ markup = 'tex')
pylab.text(1.01, -0.02, "-1", {'color' : 'k', 'fontsize' : 20})
pylab.text(1.01, 0.98, "1", {'color' : 'k', 'fontsize' : 20})
pylab.text(1.01, 0.48, "0", {'color' : 'k', 'fontsize' : 20})
## level set equations
-pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20})
+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')
## phase field equations
-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})
+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')
pylab.savefig('pfm-lsm.png')
pylab.show()
Modified: trunk/matplotlib/examples/histogram_demo.py
===================================================================
--- trunk/matplotlib/examples/histogram_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/histogram_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -15,7 +15,7 @@
xlabel('Smarts')
ylabel('Probability')
-title(r'$\rm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
+title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$', markup='tex')
axis([40, 160, 0, 0.03])
grid(True)
Modified: trunk/matplotlib/examples/histogram_demo_canvasagg.py
===================================================================
--- trunk/matplotlib/examples/histogram_demo_canvasagg.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/histogram_demo_canvasagg.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -33,7 +33,7 @@
ax.set_xlabel('Smarts')
ax.set_ylabel('Probability')
-ax.set_title(r'$\rm{Histogram of IQ: }\mu=100, \sigma=15$')
+ax.set_title(r'$\mathrm{Histogram of IQ: }\mu=100, \sigma=15$', markup='tex')
ax.set_xlim( (40, 160))
ax.set_ylim( (0, 0.03))
Modified: trunk/matplotlib/examples/integral_demo.py
===================================================================
--- trunk/matplotlib/examples/integral_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/integral_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -22,8 +22,8 @@
ax.add_patch(poly)
text(0.5 * (a + b), 30,
- r"$\int_a^b f(x)\rm{d}x$", horizontalalignment='center',
- fontsize=20)
+ r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
+ fontsize=20, markup='tex')
axis([0,10, 0, 180])
figtext(0.9, 0.05, 'x')
Modified: trunk/matplotlib/examples/legend_auto.py
===================================================================
--- trunk/matplotlib/examples/legend_auto.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/legend_auto.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -51,9 +51,9 @@
def fig_7():
figure(7)
xx = x - (N/2.0)
- plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$')
- plot(xx, 25*xx, 'go', label='$y=25x$')
- plot(xx, -25*xx, 'mo', label='$y=-25x$')
+ plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$', markup='tex')
+ plot(xx, 25*xx, 'go', label='$y=25x$', markup='tex')
+ plot(xx, -25*xx, 'mo', label='$y=-25x$', markup='tex')
legend()
def fig_8():
Modified: trunk/matplotlib/examples/mathtext_demo.py
===================================================================
--- trunk/matplotlib/examples/mathtext_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/mathtext_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -17,7 +17,7 @@
ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20)
tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$'
-ax.text(1, 1.6, tex, fontsize=20, va='bottom')
+ax.text(1, 1.6, tex, fontsize=20, va='bottom', markup="tex")
#title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
fig.savefig('mathtext_demo')
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -62,7 +62,7 @@
x = arange(0.0, 3.0, 0.1)
grid(True)
- text(1, 1.6, s, fontsize=20)
+ text(1, 1.6, s, fontsize=20, markup="tex")
savefig('mathtext_example%02d' % i)
figure()
Modified: trunk/matplotlib/examples/scatter_demo2.py
===================================================================
--- trunk/matplotlib/examples/scatter_demo2.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/scatter_demo2.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -11,8 +11,8 @@
close = 0.003*intc.close[:-2]/0.003*intc.open[:-2]
p = scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.75)
-xlabel(r'$\Delta_i$', size='x-large')
-ylabel(r'$\Delta_{i+1}$', size='x-large')
+xlabel(r'$\Delta_i$', size='x-large', markup='tex')
+ylabel(r'$\Delta_{i+1}$', size='x-large', markup='tex')
title(r'Volume and percent change')
grid(True)
#savefig('scatter_demo2')
Modified: trunk/matplotlib/examples/tex_demo.py
===================================================================
--- trunk/matplotlib/examples/tex_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/tex_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -23,10 +23,10 @@
s = cos(2*2*pi*t)+2
plot(t, s)
-xlabel(r'\textbf{time (s)}')
-ylabel(r'\textit{voltage (mV)}',fontsize=16)
+xlabel(r'\textbf{time (s)}', markup='tex')
+ylabel(r'\textit{voltage (mV)}',fontsize=16, markup='tex')
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
- fontsize=16, color='r')
+ fontsize=16, color='r', markup='tex')
grid(True)
savefig('tex_demo')
Modified: trunk/matplotlib/examples/tex_unicode_demo.py
===================================================================
--- trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -17,11 +17,11 @@
s = cos(2*2*pi*t)+2
plot(t, s)
-xlabel(r'\textbf{time (s)}')
+xlabel(r'\textbf{time (s)}', markup='tex')
s = unicode(r'\textit{Velocity (\xB0/sec)}','latin-1')
-ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16)
+ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16, markup='tex')
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
- fontsize=16, color='r')
+ fontsize=16, color='r', markup='tex')
grid(True)
savefig('tex_demo')
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -1840,6 +1840,8 @@
)
)
+ self.clear()
+
def clear(self):
self._expr = None
self._state_stack = None
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -198,6 +198,11 @@
except ValueError:
raise ValueError('not a valid font size')
+validate_markup = ValidateInStrings(
+ 'markup',
+ ['plain', 'tex'],
+ ignorecase=True)
+
validate_verbose = ValidateInStrings('verbose',[
'silent', 'helpful', 'debug', 'debug-annoying',
])
@@ -350,8 +355,8 @@
'text.fontvariant' : ['normal', str],
'text.fontweight' : ['normal', str],
'text.fontsize' : ['medium', validate_fontsize],
+ 'text.markup' : ['plain', validate_markup],
-
'image.aspect' : ['equal', validate_aspect], # equal, auto, a number
'image.interpolation' : ['bilinear', str],
'image.cmap' : ['jet', str], # one of gray, jet, etc
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/text.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -146,6 +146,7 @@
fontproperties=None, # defaults to FontProperties()
rotation=None,
linespacing=None,
+ markup=None,
**kwargs
):
"""
@@ -174,6 +175,7 @@
if linespacing is None:
linespacing = 1.2 # Maybe use rcParam later.
self._linespacing = linespacing
+ self.set_markup(markup)
self.update(kwargs)
#self.set_bbox(dict(pad=0))
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
@@ -222,6 +224,7 @@
self._rotation = other._rotation
self._picker = other._picker
self._linespacing = other._linespacing
+ self._markup = other._markup
def _get_layout(self, renderer):
@@ -752,11 +755,11 @@
self._substrings = [] # ignore embedded mathtext for now
def is_math_text(self):
- if rcParams['text.usetex']: return 'TeX'
- if not matplotlib._havemath: return False
- if len(self._text)<2: return False
- dollar_signs = self._text.count('$') - self._text.count('\\$')
- return dollar_signs > 0 and dollar_signs % 2 == 0
+ if rcParams['text.usetex']: return 'TeX'
+ if self._markup.lower() == 'tex':
+ if not matplotlib._havemath: return False
+ return True
+ return False
def set_fontproperties(self, fp):
"""
@@ -766,9 +769,20 @@
"""
self._fontproperties = fp
+ def set_markup(self, markup):
+ """
+ Set the type of markup used for this text.
+ ACCEPTS: 'plain' for plain text, 'tex' for TeX-like markup
+ None to use the default text.markup value.
+ """
+ if markup is None:
+ self._markup = rcParams['text.markup']
+ elif markup.lower() in ('plain', 'tex'):
+ self._markup = markup.lower()
+ else:
+ raise ValueError("Markup type must be 'plain' or 'tex'")
-
def _get_layout_super(self, renderer, m):
"""
a special case optimization if a log super and angle = 0
Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/matplotlibrc.template 2007-08-02 18:37:32 UTC (rev 3664)
@@ -150,6 +150,14 @@
#text.dvipnghack : False # some versions of dvipng don't handle
# alpha channel properly. Use True to correct and flush
# ~/.matplotlib/tex.cache before testing
+#text.markup : 'plain' # Affects how text, such as titles and lables, are
+ # interpreted by default.
+ # 'plain': As plain, unformatted text
+ # 'tex': As TeX-like text. Text between $'s will be
+ # formatted as a TeX math expression.
+ # This setting has no effect when text.usetex is True.
+ # In that case, all text will be sent to TeX for
+ # processing.
### AXES
# default face and edge color, default tick sizes,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|