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

Skip to content

Commit fe80816

Browse files
committed
added Daishi revised dash text patch
svn path=/trunk/matplotlib/; revision=1385
1 parent 8780a28 commit fe80816

5 files changed

Lines changed: 417 additions & 320 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ New entries should be added at the top
1616
2005-05-27 Fixed bug where 2nd wxapp could be started if using wxagg
1717
backend. - ADS
1818

19-
2005-05-26 Added Daisha text with dash patch -- see examples/dashtick.py
19+
2005-05-26 Added Daishi text with dash patch -- see examples/dashtick.py
2020

2121
2005-05-26 Moved backend_latex functionality into backend_ps. If
2222
text.usetex=True, the PostScript backend will use LaTeX to

examples/dashpointlabel.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from matplotlib import pylab
2+
3+
DATA = ((1, 3),
4+
(2, 4),
5+
(3, 1),
6+
(4, 2))
7+
# dash_style =
8+
# direction, length, (text)rotation, dashrotation, push
9+
# (The parameters are varied to show their effects,
10+
# not for visual appeal).
11+
dash_style = (
12+
(0, 20, -15, 30, 10),
13+
(1, 30, 0, 15, 10),
14+
(0, 40, 15, 15, 10),
15+
(1, 20, 30, 60, 10),
16+
)
17+
18+
def test_dashpointlabel(save=False):
19+
pylab.clf()
20+
(x,y) = zip(*DATA)
21+
pylab.plot(x, y, marker='o')
22+
for i in xrange(len(DATA)):
23+
(x,y) = DATA[i]
24+
(dd, dl, r, dr, dp) = dash_style[i]
25+
pylab.text(x, y, str((x,y)), withdash=True,
26+
dashdirection=dd,
27+
dashlength=dl,
28+
rotation=r,
29+
dashrotation=dr,
30+
dashpush=dp,
31+
)
32+
axis = pylab.gca()
33+
axis.set_xlim((0.0, 5.0))
34+
axis.set_ylim((0.0, 5.0))
35+
if save:
36+
pylab.savefig('dashpointlabel')
37+
pylab.show()
38+
39+
if __name__ == '__main__':
40+
test_dashpointlabel()

lib/matplotlib/axes.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from matplotlib import rcParams
3636
from patches import Patch, Rectangle, Circle, Polygon, Arrow, Wedge, Shadow, bbox_artist
3737
from table import Table
38-
from text import Text, _process_text_args
38+
from text import Text, TextWithDash, _process_text_args
3939
from transforms import Bbox, Point, Value, Affine, NonseparableTransformation
4040
from transforms import FuncXY, Func, LOG10, IDENTITY, POLAR
4141
from transforms import get_bbox_transform, unit_bbox, one, origin, zero
@@ -3403,7 +3403,8 @@ def table(self,
34033403
return table
34043404

34053405

3406-
def text(self, x, y, s, fontdict=None, **kwargs):
3406+
def text(self, x, y, s, fontdict=None,
3407+
withdash=False, **kwargs):
34073408
"""
34083409
TEXT(x, y, s, fontdict=None, **kwargs)
34093410
@@ -3413,6 +3414,9 @@ def text(self, x, y, s, fontdict=None, **kwargs):
34133414
If fontdict is None, the defaults are determined by your rc
34143415
parameters.
34153416
3417+
withdash=True will create a TextWithDash instance instead
3418+
of a Text instance.
3419+
34163420
Individual keyword arguemnts can be used to override any given
34173421
parameter
34183422
@@ -3437,9 +3441,20 @@ def text(self, x, y, s, fontdict=None, **kwargs):
34373441
'transform' : self.transData,
34383442
}
34393443

3440-
t = Text(
3441-
x=x, y=y, text=s,
3442-
)
3444+
# At some point if we feel confident that TextWithDash
3445+
# is robust as a drop-in replacement for Text and that
3446+
# the performance impact of the heavier-weight class
3447+
# isn't too significant, it may make sense to eliminate
3448+
# the withdash kwarg and simply delegate whether there's
3449+
# a dash to TextWithDash and dashlength.
3450+
if withdash:
3451+
t = TextWithDash(
3452+
x=x, y=y, text=s,
3453+
)
3454+
else:
3455+
t = Text(
3456+
x=x, y=y, text=s,
3457+
)
34433458
self._set_artist_props(t)
34443459

34453460
t.update(default)

0 commit comments

Comments
 (0)