Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Fixing selections and drawing in newer versions of matplotlib.

This commit is contained in:
Einar Ryeng 2009-08-22 17:41:06 +00:00
parent 14de18c507
commit 4ce6963428
2 changed files with 13 additions and 12 deletions

View File

@ -341,6 +341,7 @@ class ScatterMarkerPlot(Plot):
self.selection_listener(self.current_dim, ids) self.selection_listener(self.current_dim, ids)
def set_current_selection(self, selection): def set_current_selection(self, selection):
print "set_current_selection"
#remove old selection #remove old selection
if self._selection_line: if self._selection_line:
self.axes.lines.remove(self._selection_line) self.axes.lines.remove(self._selection_line)
@ -477,7 +478,7 @@ class ScatterPlot(Plot):
def init_draw(self): def init_draw(self):
lw = scipy.zeros(self.xaxis_data.shape) lw = scipy.zeros(self.xaxis_data.shape)
self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data, self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data, edgecolor='r',
s=self.s, c=self.c, linewidth=lw, s=self.s, c=self.c, linewidth=lw,
zorder=3, **self.kw) zorder=3, **self.kw)
self._mappable = self.sc self._mappable = self.sc
@ -486,7 +487,7 @@ class ScatterPlot(Plot):
alpha=0, alpha=0,
c='w',s=self.s, c='w',s=self.s,
edgecolor='r', edgecolor='r',
linewidth=0, linewidth=4,
zorder=4) zorder=4)
self.axes.axhline(0, color='k', lw=1., zorder=1) self.axes.axhline(0, color='k', lw=1., zorder=1)
self.axes.axvline(0, color='k', lw=1., zorder=1) self.axes.axvline(0, color='k', lw=1., zorder=1)
@ -618,7 +619,7 @@ class ScatterPlot(Plot):
index = self.get_index_from_selection(self.dataset_1, selection) index = self.get_index_from_selection(self.dataset_1, selection)
if len(index) > 0: if len(index) > 0:
linewidth[index] = 1.5 linewidth[index] = 1.5
self.selection_collection.set_linewidth(linewidth) self.sc.set_linewidth(linewidth)
if self._use_blit and len(index)>0 : if self._use_blit and len(index)>0 :
if self._background is None: if self._background is None:

View File

@ -536,12 +536,12 @@ class PanPlotMode(PlotMode):
self._xypress=[] self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()): for i, a in enumerate(self.canvas.figure.get_axes()):
if x is not None and y is not None and a.in_axes(x, y) \ if x is not None and y is not None and a.in_axes(event) \
and a.get_navigate(): and a.get_navigate():
xmin, xmax = a.get_xlim() xmin, xmax = a.get_xlim()
ymin, ymax = a.get_ylim() ymin, ymax = a.get_ylim()
lim = xmin, xmax, ymin, ymax lim = xmin, xmax, ymin, ymax
self._xypress.append((x, y, a, i, lim,a.transData.deepcopy())) self._xypress.append((x, y, a, i, lim,a.transData.frozen()))
self.canvas.mpl_disconnect(self._motion_notify) self.canvas.mpl_disconnect(self._motion_notify)
cid = self.canvas.mpl_connect('motion_notify_event', cid = self.canvas.mpl_connect('motion_notify_event',
@ -580,8 +580,8 @@ class PanPlotMode(PlotMode):
#safer to use the recorded button at the press than current button: #safer to use the recorded button at the press than current button:
#multiple button can get pressed during motion... #multiple button can get pressed during motion...
if self._button_pressed==1: if self._button_pressed==1:
lastx, lasty = trans.inverse_xy_tup( (lastx, lasty) ) lastx, lasty = trans.inverted().transform( (lastx, lasty) )
x, y = trans.inverse_xy_tup( (event.x, event.y) ) x, y = trans.inverted().transform( (event.x, event.y) )
if a.get_xscale()=='log': if a.get_xscale()=='log':
dx=1-lastx/x dx=1-lastx/x
else: else:
@ -608,15 +608,15 @@ class PanPlotMode(PlotMode):
elif self._button_pressed==3: elif self._button_pressed==3:
try: try:
dx=(lastx-event.x)/float(a.bbox.width()) dx=(lastx-event.x)/float(a.bbox.width)
dy=(lasty-event.y)/float(a.bbox.height()) dy=(lasty-event.y)/float(a.bbox.height)
dx,dy=format_deltas(event,dx,dy) dx,dy=format_deltas(event,dx,dy)
if a.get_aspect() != 'auto': if a.get_aspect() != 'auto':
dx = 0.5*(dx + dy) dx = 0.5*(dx + dy)
dy = dx dy = dx
alphax = pow(10.0,dx) alphax = pow(10.0,dx)
alphay = pow(10.0,dy) alphay = pow(10.0,dy)
lastx, lasty = trans.inverse_xy_tup( (lastx, lasty) ) lastx, lasty = trans.inverted().transform( (lastx, lasty) )
if a.get_xscale()=='log': if a.get_xscale()=='log':
xmin = lastx*(xmin/lastx)**alphax xmin = lastx*(xmin/lastx)**alphax
xmax = lastx*(xmax/lastx)**alphax xmax = lastx*(xmax/lastx)**alphax
@ -934,8 +934,8 @@ class Selector:
miny, maxy = self.eventpress.ydata, y miny, maxy = self.eventpress.ydata, y
if minx>maxx: minx, maxx = maxx, minx if minx>maxx: minx, maxx = maxx, minx
if miny>maxy: miny, maxy = maxy, miny if miny>maxy: miny, maxy = maxy, miny
self.polygon.xy[0] = minx self.polygon.set_x(minx)
self.polygon.xy[1] = miny self.polygon.set_y(miny)
self.polygon.set_width(maxx-minx) self.polygon.set_width(maxx-minx)
self.polygon.set_height(maxy-miny) self.polygon.set_height(maxy-miny)
xx = [minx, maxx, maxx, minx, minx] xx = [minx, maxx, maxx, minx, minx]