Skip to content

Commit

Permalink
Simplified sharing axes again.
Browse files Browse the repository at this point in the history
Plowing through -- making more examples work.
First pass at updating collections (LineCollection mostly works)

svn path=/branches/transforms/; revision=3924
  • Loading branch information
mdboom committed Oct 5, 2007
1 parent b7d1d59 commit 8baa717
Show file tree
Hide file tree
Showing 19 changed files with 978 additions and 741 deletions.
15 changes: 2 additions & 13 deletions examples/clippath_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ def __init__(self, ax, line):
self.poly = RegularPolygon(
(200, 200), numVertices=10, radius=100,
facecolor='yellow', alpha=0.25,
transform=transforms.identity_transform())
transform=transforms.IdentityTransform())

ax.add_patch(self.poly)
self.canvas.mpl_connect('button_press_event', self.onpress)
self.canvas.mpl_connect('button_release_event', self.onrelease)
self.canvas.mpl_connect('motion_notify_event', self.onmove)
self.x, self.y = None, None


def onpress(self, event):
self.x, self.y = event.x, event.y

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

def _clip(self):
fig = self.ax.figure
l,b,w,h = fig.bbox.get_bounds()
path = agg.path_storage()

for i, xy in enumerate(self.poly.get_verts()):
x,y = xy
y = h-y
if i==0: path.move_to(x,y)
else: path.line_to(x,y)
path.close_polygon()
self.line.set_clip_path(path)
self.line.set_clip_path(self.poly.get_path(), self.poly.get_transform())
self.canvas.draw_idle()


Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def get_clip_path(self):
'Return artist clip path'
return self._clippath

def get_transformed_clip_path_and_affine(self):
if self._clippath is not None:
return self._clippath.get_transformed_path_and_affine()
return None, None

def set_clip_on(self, b):
"""
Set whether artist uses clipping
Expand Down
48 changes: 27 additions & 21 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,9 @@ def __init__(self, fig, rect,
self._sharey = sharey
if sharex is not None:
self._shared_x_axes.join(self, sharex)
if sharey is not None:
if sharey is not None:
self._shared_y_axes.join(self, sharey)
# Flag: True if some other Axes instance is sharing our x or y axis
self._masterx = False
self._mastery = False
if sharex: sharex._masterx = True
if sharey: sharey._mastery = True

self.set_label(label)
self.set_figure(fig)

Expand Down Expand Up @@ -822,7 +818,8 @@ def apply_aspect(self):
Use self._aspect and self._adjustable to modify the
axes box or the view limits.
'''

#MGDTODO: Numpify

if self._aspect == 'auto':
self.set_position( self._originalPosition , 'active')
return
Expand All @@ -834,7 +831,7 @@ def apply_aspect(self):

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

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


xmin,xmax = self.get_xlim()
xsize = max(math.fabs(xmax-xmin), 1e-30)
ymin,ymax = self.get_ylim()
ysize = max(math.fabs(ymax-ymin), 1e-30)

l,b,w,h = self.get_position(original=True).bounds
box_aspect = fig_aspect * (h/w)
data_ratio = box_aspect / A
Expand All @@ -858,8 +860,8 @@ def apply_aspect(self):
#print 'good enough already'
return
dL = self.dataLim
xr = 1.05 * dL.width()
yr = 1.05 * dL.height()
xr = 1.05 * dL.width
yr = 1.05 * dL.height
xmarg = xsize - xr
ymarg = ysize - yr
Ysize = data_ratio * xsize
Expand All @@ -871,10 +873,10 @@ def apply_aspect(self):
#print 'xmin, xmax, ymin, ymax', xmin, xmax, ymin, ymax
#print 'xsize, Xsize, ysize, Ysize', xsize, Xsize, ysize, Ysize

changex = ((self._sharey or self._mastery) and not
(self._sharex or self._masterx))
changey = ((self._sharex or self._masterx) and not
(self._sharey or self._mastery))
changex = (self in self._shared_y_axes
and self not in self._shared_x_axes)
changey = (self in self._shared_x_axes
and self not in self._shared_y_axes)
if changex and changey:
warnings.warn("adjustable='datalim' cannot work with shared x and y axes")
return
Expand Down Expand Up @@ -2200,7 +2202,8 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
%(Line2D)s
"""

trans = mtransforms.blend_xy_sep_transform(self.transAxes, self.transData)
trans = mtransforms.blended_transform_factory(
self.transAxes, self.transData)
l, = self.plot([xmin,xmax], [y,y], transform=trans, scalex=False, **kwargs)
return l

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

trans = mtransforms.blend_xy_sep_transform( self.transData, self.transAxes )
trans = mtransforms.blended_transform_factory(
self.transData, self.transAxes)
l, = self.plot([x,x], [ymin,ymax] , transform=trans, scaley=False, **kwargs)
return l

Expand Down Expand Up @@ -2275,7 +2279,8 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
%(Polygon)s
"""
# convert y axis units
trans = mtransforms.blend_xy_sep_transform( self.transAxes, self.transData)
trans = mtransforms.blended_transform_factory(
self.transAxes, self.transData)
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
p = mpatches.Polygon(verts, **kwargs)
p.set_transform(trans)
Expand Down Expand Up @@ -2315,7 +2320,8 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
%(Polygon)s
"""
# convert x axis units
trans = mtransforms.blend_xy_sep_transform(self.transData, self.transAxes)
trans = mtransforms.blended_transform_factory(
self.transData, self.transAxes)
verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
p = mpatches.Polygon(verts, **kwargs)
p.set_transform(trans)
Expand Down Expand Up @@ -2386,7 +2392,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyle='solid',
return coll
hlines.__doc__ = cbook.dedent(hlines.__doc__)

def vlines(self, x, ymin, ymax, colors='k', linestyle='solid',
def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
label='', **kwargs):
"""
VLINES(x, ymin, ymax, color='k')
Expand Down Expand Up @@ -2438,7 +2444,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyle='solid',
for thisx, (thisymin, thisymax) in zip(x,Y)]
#print 'creating line collection'
coll = mcoll.LineCollection(verts, colors=colors,
linestyle=linestyle, label=label)
linestyles=linestyles, label=label)
self.add_collection(coll)
coll.update(kwargs)

Expand Down Expand Up @@ -3660,7 +3666,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
else:
lower = y-yerr[0]
upper = y+yerr[1]

barcols.append( self.vlines(x, lower, upper, **lines_kw) )
if capsize > 0:

Expand Down
16 changes: 12 additions & 4 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,9 @@ def set_ticks_position(self, position):
default resets the tick positions to the default:
ticks on both positions, labels at bottom.
ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' ]
ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' | 'none' ]
"""
assert position == 'top' or position == 'bottom' or position == 'both' or position == 'default'
assert position in ('top', 'bottom', 'both', 'default', 'none')


ticks = list( self.get_major_ticks() ) # a copy
Expand All @@ -1124,6 +1124,10 @@ def set_ticks_position(self, position):
t.tick2On = True
t.label1On = True
t.label2On = False
elif position == 'none':
for t in ticks:
t.tick1On = False
t.tick2On = False
else:
for t in ticks:
t.tick1On = True
Expand Down Expand Up @@ -1306,9 +1310,9 @@ def set_ticks_position(self, position):
default resets the tick positions to the default:
ticks on both positions, labels on the left.
ACCEPTS: [ 'left' | 'right' | 'both' | 'default' ]
ACCEPTS: [ 'left' | 'right' | 'both' | 'default' | 'none' ]
"""
assert position == 'left' or position == 'right' or position == 'both' or position == 'default'
assert position in ('left', 'right', 'both', 'default', 'none')

ticks = list( self.get_major_ticks() ) # a copy
ticks.extend( self.get_minor_ticks() )
Expand All @@ -1334,6 +1338,10 @@ def set_ticks_position(self, position):
t.tick2On = True
t.label1On = True
t.label2On = False
elif position == 'none':
for t in ticks:
t.tick1On = False
t.tick2On = False
else:
self.set_offset_position('left')
for t in ticks:
Expand Down
Loading

0 comments on commit 8baa717

Please sign in to comment.