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

Skip to content

Commit 8baa717

Browse files
committed
Simplified sharing axes again.
Plowing through -- making more examples work. First pass at updating collections (LineCollection mostly works) svn path=/branches/transforms/; revision=3924
1 parent b7d1d59 commit 8baa717

19 files changed

Lines changed: 978 additions & 741 deletions

examples/clippath_test.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ def __init__(self, ax, line):
1313
self.poly = RegularPolygon(
1414
(200, 200), numVertices=10, radius=100,
1515
facecolor='yellow', alpha=0.25,
16-
transform=transforms.identity_transform())
16+
transform=transforms.IdentityTransform())
1717

1818
ax.add_patch(self.poly)
1919
self.canvas.mpl_connect('button_press_event', self.onpress)
2020
self.canvas.mpl_connect('button_release_event', self.onrelease)
2121
self.canvas.mpl_connect('motion_notify_event', self.onmove)
2222
self.x, self.y = None, None
2323

24-
2524
def onpress(self, event):
2625
self.x, self.y = event.x, event.y
2726

@@ -42,17 +41,7 @@ def onmove(self, event):
4241
self._clip()
4342

4443
def _clip(self):
45-
fig = self.ax.figure
46-
l,b,w,h = fig.bbox.get_bounds()
47-
path = agg.path_storage()
48-
49-
for i, xy in enumerate(self.poly.get_verts()):
50-
x,y = xy
51-
y = h-y
52-
if i==0: path.move_to(x,y)
53-
else: path.line_to(x,y)
54-
path.close_polygon()
55-
self.line.set_clip_path(path)
44+
self.line.set_clip_path(self.poly.get_path(), self.poly.get_transform())
5645
self.canvas.draw_idle()
5746

5847

lib/matplotlib/artist.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ def get_clip_path(self):
335335
'Return artist clip path'
336336
return self._clippath
337337

338+
def get_transformed_clip_path_and_affine(self):
339+
if self._clippath is not None:
340+
return self._clippath.get_transformed_path_and_affine()
341+
return None, None
342+
338343
def set_clip_on(self, b):
339344
"""
340345
Set whether artist uses clipping

lib/matplotlib/axes.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,9 @@ def __init__(self, fig, rect,
488488
self._sharey = sharey
489489
if sharex is not None:
490490
self._shared_x_axes.join(self, sharex)
491-
if sharey is not None:
491+
if sharey is not None:
492492
self._shared_y_axes.join(self, sharey)
493-
# Flag: True if some other Axes instance is sharing our x or y axis
494-
self._masterx = False
495-
self._mastery = False
496-
if sharex: sharex._masterx = True
497-
if sharey: sharey._mastery = True
493+
498494
self.set_label(label)
499495
self.set_figure(fig)
500496

@@ -822,7 +818,8 @@ def apply_aspect(self):
822818
Use self._aspect and self._adjustable to modify the
823819
axes box or the view limits.
824820
'''
825-
821+
#MGDTODO: Numpify
822+
826823
if self._aspect == 'auto':
827824
self.set_position( self._originalPosition , 'active')
828825
return
@@ -834,7 +831,7 @@ def apply_aspect(self):
834831

835832
#Ensure at drawing time that any Axes involved in axis-sharing
836833
# does not have its position changed.
837-
if self._masterx or self._mastery or self._sharex or self._sharey:
834+
if self in self._shared_x_axes or self in self._shared_y_axes:
838835
self._adjustable = 'datalim'
839836

840837
figW,figH = self.get_figure().get_size_inches()
@@ -847,6 +844,11 @@ def apply_aspect(self):
847844
return
848845

849846

847+
xmin,xmax = self.get_xlim()
848+
xsize = max(math.fabs(xmax-xmin), 1e-30)
849+
ymin,ymax = self.get_ylim()
850+
ysize = max(math.fabs(ymax-ymin), 1e-30)
851+
850852
l,b,w,h = self.get_position(original=True).bounds
851853
box_aspect = fig_aspect * (h/w)
852854
data_ratio = box_aspect / A
@@ -858,8 +860,8 @@ def apply_aspect(self):
858860
#print 'good enough already'
859861
return
860862
dL = self.dataLim
861-
xr = 1.05 * dL.width()
862-
yr = 1.05 * dL.height()
863+
xr = 1.05 * dL.width
864+
yr = 1.05 * dL.height
863865
xmarg = xsize - xr
864866
ymarg = ysize - yr
865867
Ysize = data_ratio * xsize
@@ -871,10 +873,10 @@ def apply_aspect(self):
871873
#print 'xmin, xmax, ymin, ymax', xmin, xmax, ymin, ymax
872874
#print 'xsize, Xsize, ysize, Ysize', xsize, Xsize, ysize, Ysize
873875

874-
changex = ((self._sharey or self._mastery) and not
875-
(self._sharex or self._masterx))
876-
changey = ((self._sharex or self._masterx) and not
877-
(self._sharey or self._mastery))
876+
changex = (self in self._shared_y_axes
877+
and self not in self._shared_x_axes)
878+
changey = (self in self._shared_x_axes
879+
and self not in self._shared_y_axes)
878880
if changex and changey:
879881
warnings.warn("adjustable='datalim' cannot work with shared x and y axes")
880882
return
@@ -2200,7 +2202,8 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
22002202
%(Line2D)s
22012203
"""
22022204

2203-
trans = mtransforms.blend_xy_sep_transform(self.transAxes, self.transData)
2205+
trans = mtransforms.blended_transform_factory(
2206+
self.transAxes, self.transData)
22042207
l, = self.plot([xmin,xmax], [y,y], transform=trans, scalex=False, **kwargs)
22052208
return l
22062209

@@ -2236,7 +2239,8 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
22362239
%(Line2D)s
22372240
"""
22382241

2239-
trans = mtransforms.blend_xy_sep_transform( self.transData, self.transAxes )
2242+
trans = mtransforms.blended_transform_factory(
2243+
self.transData, self.transAxes)
22402244
l, = self.plot([x,x], [ymin,ymax] , transform=trans, scaley=False, **kwargs)
22412245
return l
22422246

@@ -2275,7 +2279,8 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
22752279
%(Polygon)s
22762280
"""
22772281
# convert y axis units
2278-
trans = mtransforms.blend_xy_sep_transform( self.transAxes, self.transData)
2282+
trans = mtransforms.blended_transform_factory(
2283+
self.transAxes, self.transData)
22792284
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
22802285
p = mpatches.Polygon(verts, **kwargs)
22812286
p.set_transform(trans)
@@ -2315,7 +2320,8 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
23152320
%(Polygon)s
23162321
"""
23172322
# convert x axis units
2318-
trans = mtransforms.blend_xy_sep_transform(self.transData, self.transAxes)
2323+
trans = mtransforms.blended_transform_factory(
2324+
self.transData, self.transAxes)
23192325
verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
23202326
p = mpatches.Polygon(verts, **kwargs)
23212327
p.set_transform(trans)
@@ -2386,7 +2392,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyle='solid',
23862392
return coll
23872393
hlines.__doc__ = cbook.dedent(hlines.__doc__)
23882394

2389-
def vlines(self, x, ymin, ymax, colors='k', linestyle='solid',
2395+
def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
23902396
label='', **kwargs):
23912397
"""
23922398
VLINES(x, ymin, ymax, color='k')
@@ -2438,7 +2444,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyle='solid',
24382444
for thisx, (thisymin, thisymax) in zip(x,Y)]
24392445
#print 'creating line collection'
24402446
coll = mcoll.LineCollection(verts, colors=colors,
2441-
linestyle=linestyle, label=label)
2447+
linestyles=linestyles, label=label)
24422448
self.add_collection(coll)
24432449
coll.update(kwargs)
24442450

@@ -3660,7 +3666,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
36603666
else:
36613667
lower = y-yerr[0]
36623668
upper = y+yerr[1]
3663-
3669+
36643670
barcols.append( self.vlines(x, lower, upper, **lines_kw) )
36653671
if capsize > 0:
36663672

lib/matplotlib/axis.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,9 @@ def set_ticks_position(self, position):
10981098
default resets the tick positions to the default:
10991099
ticks on both positions, labels at bottom.
11001100
1101-
ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' ]
1101+
ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' | 'none' ]
11021102
"""
1103-
assert position == 'top' or position == 'bottom' or position == 'both' or position == 'default'
1103+
assert position in ('top', 'bottom', 'both', 'default', 'none')
11041104

11051105

11061106
ticks = list( self.get_major_ticks() ) # a copy
@@ -1124,6 +1124,10 @@ def set_ticks_position(self, position):
11241124
t.tick2On = True
11251125
t.label1On = True
11261126
t.label2On = False
1127+
elif position == 'none':
1128+
for t in ticks:
1129+
t.tick1On = False
1130+
t.tick2On = False
11271131
else:
11281132
for t in ticks:
11291133
t.tick1On = True
@@ -1306,9 +1310,9 @@ def set_ticks_position(self, position):
13061310
default resets the tick positions to the default:
13071311
ticks on both positions, labels on the left.
13081312
1309-
ACCEPTS: [ 'left' | 'right' | 'both' | 'default' ]
1313+
ACCEPTS: [ 'left' | 'right' | 'both' | 'default' | 'none' ]
13101314
"""
1311-
assert position == 'left' or position == 'right' or position == 'both' or position == 'default'
1315+
assert position in ('left', 'right', 'both', 'default', 'none')
13121316

13131317
ticks = list( self.get_major_ticks() ) # a copy
13141318
ticks.extend( self.get_minor_ticks() )
@@ -1334,6 +1338,10 @@ def set_ticks_position(self, position):
13341338
t.tick2On = True
13351339
t.label1On = True
13361340
t.label2On = False
1341+
elif position == 'none':
1342+
for t in ticks:
1343+
t.tick1On = False
1344+
t.tick2On = False
13371345
else:
13381346
self.set_offset_position('left')
13391347
for t in ticks:

0 commit comments

Comments
 (0)