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

Skip to content

Commit 97bc004

Browse files
committed
Allow markup kwarg in more places.
svn path=/trunk/matplotlib/; revision=3741
1 parent 4859243 commit 97bc004

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

examples/quiver_demo.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#1
1818
figure()
1919
Q = quiver( U, V)
20-
qk = quiverkey(Q, 0.5, 0.92, 2, '2 m/s', labelpos='W',
21-
fontproperties={'weight': 'bold'})
20+
qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
21+
fontproperties={'weight': 'bold'},
22+
markup="tex")
2223
l,r,b,t = axis()
2324
dx, dy = r-l, t-b
2425
axis([l-0.05*dx, r+0.05*dx, b-0.05*dy, t+0.05*dy])
@@ -28,18 +29,19 @@
2829
#2
2930
figure()
3031
Q = quiver( X, Y, U, V, units='width')
31-
qk = quiverkey(Q, 0.9, 0.95, 2, '2 m/s',
32-
labelpos='E',
33-
coordinates='figure',
34-
fontproperties={'weight': 'bold'})
32+
qk = quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$',
33+
labelpos='E',
34+
coordinates='figure',
35+
fontproperties={'weight': 'bold'},
36+
markup="tex")
3537
axis([-1, 7, -1, 7])
3638
title('scales with plot width, not view')
3739

3840
#3
3941
figure()
4042
Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
4143
pivot='mid', color='r', units='inches' )
42-
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s', fontproperties={'weight': 'bold'})
44+
qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}, markup="tex")
4345
plot( X[::3, ::3], Y[::3, ::3], 'k.')
4446
axis([-1, 7, -1, 7])
4547
title("pivot='mid'; every third arrow; units='inches'")
@@ -48,9 +50,10 @@
4850
figure()
4951
M = sqrt(pow(U, 2) + pow(V, 2))
5052
Q = quiver( X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1/0.15)
51-
qk = quiverkey(Q, 0.9, 1.05, 1, '1 m/s',
53+
qk = quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$',
5254
labelpos='E',
53-
fontproperties={'weight': 'bold'})
55+
fontproperties={'weight': 'bold'},
56+
markup="tex")
5457
plot(X, Y, 'k.')
5558
axis([-1, 7, -1, 7])
5659
title("scales with x view; pivot='tip'")
@@ -60,7 +63,7 @@
6063
Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
6164
color='r', units='x',
6265
linewidths=(2,), edgecolors=('k'), headaxislength=5 )
63-
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s', fontproperties={'weight': 'bold'})
66+
qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}, markup="tex")
6467
axis([-1, 7, -1, 7])
6568
title("triangular head; scale with x view; black edges")
6669

lib/matplotlib/legend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def __init__(self, parent, handles, labels,
123123
handletextsep = None, # the space between the legend line and legend text
124124
axespad = None, # the border between the axes and legend edge
125125

126-
shadow= None,
126+
shadow = None,
127+
markup = None
127128
):
128129
"""
129130
parent # the artist that contains the legend
@@ -203,7 +204,7 @@ def __init__(self, parent, handles, labels,
203204
else:
204205
self._xdata = npy.linspace(left, left + self.handlelen, self.numpoints)
205206
textleft = left+ self.handlelen+self.handletextsep
206-
self.texts = self._get_texts(labels, textleft, top)
207+
self.texts = self._get_texts(labels, textleft, top, markup)
207208
self.legendHandles = self._get_handles(handles, self.texts)
208209

209210

@@ -404,7 +405,7 @@ def get_texts(self):
404405
'return a list of text.Text instance in the legend'
405406
return silent_list('Text', self.texts)
406407

407-
def _get_texts(self, labels, left, upper):
408+
def _get_texts(self, labels, left, upper, markup):
408409

409410
# height in axes coords
410411
HEIGHT = self._approx_text_height()
@@ -419,6 +420,7 @@ def _get_texts(self, labels, left, upper):
419420
fontproperties=self.prop,
420421
verticalalignment='top',
421422
horizontalalignment='left',
423+
markup=markup
422424
)
423425
self._set_artist_props(text)
424426
ret.append(text)

lib/matplotlib/quiver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ def __init__(self, Q, X, Y, U, label, **kw):
173173
self.labelpos = kw.pop('labelpos', 'N')
174174
self.labelcolor = kw.pop('labelcolor', None)
175175
self.fontproperties = kw.pop('fontproperties', dict())
176+
self.markup = kw.pop('markup', None)
176177
self.kw = kw
177178
_fp = self.fontproperties
178179
self.text = text.Text(text=label,
179180
horizontalalignment=self.halign[self.labelpos],
180181
verticalalignment=self.valign[self.labelpos],
181-
fontproperties=font_manager.FontProperties(**_fp))
182+
fontproperties=font_manager.FontProperties(**_fp),
183+
markup=self.markup)
182184
if self.labelcolor is not None:
183185
self.text.set_color(self.labelcolor)
184186
self._initialized = False

lib/matplotlib/table.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __init__(self, xy, width, height,
4747
fill=True,
4848
text='',
4949
loc=None,
50+
fontproperties=None,
51+
markup=None
5052
):
5153

5254
# Call base
@@ -58,7 +60,8 @@ def __init__(self, xy, width, height,
5860
# Create text object
5961
if loc is None: loc = 'right'
6062
self._loc = loc
61-
self._text = Text(x=xy[0], y=xy[1], text=text)
63+
self._text = Text(x=xy[0], y=xy[1], text=text,
64+
fontproperties=fontproperties, markup=markup)
6265
self._text.set_clip_on(False)
6366

6467

0 commit comments

Comments
 (0)