Skip to content

Commit b2e04af

Browse files
committed
Merged revisions 8788 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8788 | leejjoon | 2010-11-10 18:32:58 +0900 (Wed, 10 Nov 2010) | 1 line fix incorrect end position of FancyArrowPatch ........ svn path=/trunk/matplotlib/; revision=8789
1 parent 7c8bfb4 commit b2e04af

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

lib/matplotlib/patches.py

+45-34
Original file line numberDiff line numberDiff line change
@@ -2899,29 +2899,12 @@ def __init__(self, beginarrow=None, endarrow=None,
28992899
super(ArrowStyle._Curve, self).__init__()
29002900

29012901

2902-
def _get_pad_projected(self, x0, y0, x1, y1, linewidth):
2903-
# when no arrow head is drawn
2904-
2905-
dx, dy = x0 - x1, y0 - y1
2906-
cp_distance = math.sqrt(dx**2 + dy**2)
2907-
2908-
# padx_projected, pady_projected : amount of pad to account
2909-
# projection of the wedge
2910-
padx_projected = (.5*linewidth)
2911-
pady_projected = (.5*linewidth)
2912-
2913-
# apply pad for projected edge
2914-
ddx = padx_projected * dx / cp_distance
2915-
ddy = pady_projected * dy / cp_distance
2916-
2917-
return ddx, ddy
2918-
29192902
def _get_arrow_wedge(self, x0, y0, x1, y1,
29202903
head_dist, cos_t, sin_t, linewidth
29212904
):
29222905
"""
29232906
Return the paths for arrow heads. Since arrow lines are
2924-
drawn with capstyle=projected, The arrow is goes beyond the
2907+
drawn with capstyle=projected, The arrow goes beyond the
29252908
desired point. This method also returns the amount of the path
29262909
to be shrinked so that it does not overshoot.
29272910
"""
@@ -2932,14 +2915,13 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
29322915
dx, dy = x0 - x1, y0 - y1
29332916
cp_distance = math.sqrt(dx**2 + dy**2)
29342917

2935-
# padx_projected, pady_projected : amount of pad for account
2936-
# the overshooting of the projection of the wedge
2937-
padx_projected = (.5*linewidth / cos_t)
2938-
pady_projected = (.5*linewidth / sin_t)
2918+
# pad_projected : amount of pad to account the
2919+
# overshooting of the projection of the wedge
2920+
pad_projected = (.5*linewidth / sin_t)
29392921

29402922
# apply pad for projected edge
2941-
ddx = padx_projected * dx / cp_distance
2942-
ddy = pady_projected * dy / cp_distance
2923+
ddx = pad_projected * dx / cp_distance
2924+
ddy = pad_projected * dy / cp_distance
29432925

29442926
# offset for arrow wedge
29452927
dx, dy = dx / cp_distance * head_dist, dy / cp_distance * head_dist
@@ -2948,7 +2930,7 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
29482930
dx2, dy2 = cos_t * dx - sin_t * dy, sin_t * dx + cos_t * dy
29492931

29502932
vertices_arrow = [(x1+ddx+dx1, y1+ddy+dy1),
2951-
(x1+ddx, y1++ddy),
2933+
(x1+ddx, y1+ddy),
29522934
(x1+ddx+dx2, y1+ddy+dy2)]
29532935
codes_arrow = [Path.MOVETO,
29542936
Path.LINETO,
@@ -3625,6 +3607,7 @@ def __init__(self, posA=None, posB=None,
36253607
shrinkB=2.,
36263608
mutation_scale=1.,
36273609
mutation_aspect=None,
3610+
dpi_cor=1.,
36283611
**kwargs):
36293612
"""
36303613
If *posA* and *posB* is given, a path connecting two point are
@@ -3692,8 +3675,26 @@ def __init__(self, posA=None, posB=None,
36923675
self._mutation_scale=mutation_scale
36933676
self._mutation_aspect=mutation_aspect
36943677

3678+
self.set_dpi_cor(dpi_cor)
36953679
#self._draw_in_display_coordinate = True
36963680

3681+
def set_dpi_cor(self, dpi_cor):
3682+
"""
3683+
dpi_cor is currently used for linewidth-related things and
3684+
shink factor. Mutation scale is not affected by this.
3685+
"""
3686+
3687+
self._dpi_cor = dpi_cor
3688+
3689+
def get_dpi_cor(self):
3690+
"""
3691+
dpi_cor is currently used for linewidth-related things and
3692+
shink factor. Mutation scale is not affected by this.
3693+
"""
3694+
3695+
return self._dpi_cor
3696+
3697+
36973698
def set_positions(self, posA, posB):
36983699
""" set the begin end end positions of the connecting
36993700
path. Use current vlaue if None.
@@ -3814,8 +3815,8 @@ def get_mutation_aspect(self):
38143815
def get_path(self):
38153816
"""
38163817
return the path of the arrow in the data coordinate. Use
3817-
get_path_in_displaycoord() medthod to retrieve the arrow path
3818-
in the disaply coord.
3818+
get_path_in_displaycoord() method to retrieve the arrow path
3819+
in the disaply coord.
38193820
"""
38203821
_path, fillable = self.get_path_in_displaycoord()
38213822

@@ -3830,14 +3831,16 @@ def get_path_in_displaycoord(self):
38303831
Return the mutated path of the arrow in the display coord
38313832
"""
38323833

3834+
dpi_cor = self.get_dpi_cor()
3835+
38333836
if self._posA_posB is not None:
38343837
posA = self.get_transform().transform_point(self._posA_posB[0])
38353838
posB = self.get_transform().transform_point(self._posA_posB[1])
38363839
_path = self.get_connectionstyle()(posA, posB,
38373840
patchA=self.patchA,
38383841
patchB=self.patchB,
3839-
shrinkA=self.shrinkA,
3840-
shrinkB=self.shrinkB
3842+
shrinkA=self.shrinkA*dpi_cor,
3843+
shrinkB=self.shrinkB*dpi_cor
38413844
)
38423845
else:
38433846
_path = self.get_transform().transform_path(self._path_original)
@@ -3846,7 +3849,7 @@ def get_path_in_displaycoord(self):
38463849

38473850
_path, fillable = self.get_arrowstyle()(_path,
38483851
self.get_mutation_scale(),
3849-
self.get_linewidth(),
3852+
self.get_linewidth()*dpi_cor,
38503853
self.get_mutation_aspect()
38513854
)
38523855

@@ -3887,7 +3890,11 @@ def draw(self, renderer):
38873890
if self._hatch:
38883891
gc.set_hatch(self._hatch )
38893892

3890-
3893+
# FIXME : dpi_cor is for the dpi-dependecy of the
3894+
# linewidth. There could be room for improvement.
3895+
#
3896+
#dpi_cor = renderer.points_to_pixels(1.)
3897+
self.set_dpi_cor(renderer.points_to_pixels(1.))
38913898
path, fillable = self.get_path_in_displaycoord()
38923899

38933900
if not cbook.iterable(fillable):
@@ -3940,6 +3947,7 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
39403947
mutation_scale=10.,
39413948
mutation_aspect=None,
39423949
clip_on=False,
3950+
dpi_cor=1.,
39433951
**kwargs):
39443952
"""
39453953
Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*
@@ -4013,6 +4021,7 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
40134021
mutation_scale=mutation_scale,
40144022
mutation_aspect=mutation_aspect,
40154023
clip_on=clip_on,
4024+
dpi_cor=dpi_cor,
40164025
**kwargs)
40174026

40184027
# if True, draw annotation only if self.xy is inside the axes
@@ -4144,6 +4153,8 @@ def get_path_in_displaycoord(self):
41444153
Return the mutated path of the arrow in the display coord
41454154
"""
41464155

4156+
dpi_cor = self.get_dpi_cor()
4157+
41474158
x, y = self.xy1
41484159
posA = self._get_xy(x, y, self.coords1, self.axesA)
41494160

@@ -4153,15 +4164,15 @@ def get_path_in_displaycoord(self):
41534164
_path = self.get_connectionstyle()(posA, posB,
41544165
patchA=self.patchA,
41554166
patchB=self.patchB,
4156-
shrinkA=self.shrinkA,
4157-
shrinkB=self.shrinkB
4167+
shrinkA=self.shrinkA*dpi_cor,
4168+
shrinkB=self.shrinkB*dpi_cor
41584169
)
41594170

41604171

41614172

41624173
_path, fillable = self.get_arrowstyle()(_path,
41634174
self.get_mutation_scale(),
4164-
self.get_linewidth(),
4175+
self.get_linewidth()*dpi_cor,
41654176
self.get_mutation_aspect()
41664177
)
41674178

0 commit comments

Comments
 (0)