Added colorbar shortcut
This commit is contained in:
parent
fefaffb2e3
commit
31ac569c3e
|
@ -39,11 +39,14 @@ class Plot(view.View):
|
||||||
def _init_mpl(self):
|
def _init_mpl(self):
|
||||||
# init matplotlib related stuff
|
# init matplotlib related stuff
|
||||||
self._background = None
|
self._background = None
|
||||||
|
self._colorbar = None
|
||||||
self._use_blit = False
|
self._use_blit = False
|
||||||
self.fig = Figure()
|
self.fig = Figure()
|
||||||
self.canvas = FigureCanvasGTKAgg(self.fig)
|
self.canvas = FigureCanvasGTKAgg(self.fig)
|
||||||
self.axes = self.fig.gca()
|
self.axes = self.fig.gca()
|
||||||
self._toolbar = view.PlotToolbar(self)
|
self._toolbar = view.PlotToolbar(self)
|
||||||
|
self._key_press = self.canvas.mpl_connect(
|
||||||
|
'key_press_event', self.on_key_press)
|
||||||
self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
@ -127,6 +130,34 @@ class Plot(view.View):
|
||||||
if not ids : return []
|
if not ids : return []
|
||||||
return dataset.get_indices(self.current_dim, ids)
|
return dataset.get_indices(self.current_dim, ids)
|
||||||
|
|
||||||
|
def on_key_press(self, event):
|
||||||
|
if event.key == 'c':
|
||||||
|
self._toggle_colorbar()
|
||||||
|
|
||||||
|
def _toggle_colorbar(self):
|
||||||
|
if self._colorbar == None:
|
||||||
|
# get last created instance of mappable
|
||||||
|
if not self._mappable:
|
||||||
|
self._mappable = matplotlib.pylab.gci()
|
||||||
|
if self._mappable == None:
|
||||||
|
print "No mappable"
|
||||||
|
return
|
||||||
|
if self._mappable._A != None: # we need colormapping
|
||||||
|
# get axes original position
|
||||||
|
self._ax_last_pos = self.axes.get_position()
|
||||||
|
self._colorbar = self.fig.colorbar(self._mappable)
|
||||||
|
self._colorbar.draw_all()
|
||||||
|
self.canvas.draw()
|
||||||
|
else:
|
||||||
|
# remove colorbar
|
||||||
|
# remove, axes, observers, colorbar instance, and restore viewlims
|
||||||
|
cb, ax = self._mappable.colorbar
|
||||||
|
self.fig.delaxes(ax)
|
||||||
|
self._mappable.observers = [obs for obs in self._mappable.observers if obs !=self._colorbar]
|
||||||
|
self._colorbar = None
|
||||||
|
self.axes.set_position(self._ax_last_pos)
|
||||||
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
||||||
class LineViewPlot(Plot):
|
class LineViewPlot(Plot):
|
||||||
"""Line view plot with percentiles.
|
"""Line view plot with percentiles.
|
||||||
|
@ -170,7 +201,7 @@ class LineViewPlot(Plot):
|
||||||
def _set_background(self, ax):
|
def _set_background(self, ax):
|
||||||
"""Add three patches representing [min max],[5,95] and [25,75] percentiles, and a line at the median.
|
"""Add three patches representing [min max],[5,95] and [25,75] percentiles, and a line at the median.
|
||||||
"""
|
"""
|
||||||
if self._data.shape[self.minor_axis]<10:
|
if self._data.shape[self.minor_axis]<6:
|
||||||
return
|
return
|
||||||
# settings
|
# settings
|
||||||
patch_color = 'b' #blue
|
patch_color = 'b' #blue
|
||||||
|
@ -368,6 +399,7 @@ class ScatterPlot(Plot):
|
||||||
self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data,
|
self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data,
|
||||||
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.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)
|
||||||
self.selection_collection = self.axes.scatter(self.xaxis_data,
|
self.selection_collection = self.axes.scatter(self.xaxis_data,
|
||||||
|
@ -470,6 +502,7 @@ class ImagePlot(Plot):
|
||||||
self.axes.grid(False)
|
self.axes.grid(False)
|
||||||
self.axes.imshow(dataset.asarray(), interpolation='nearest')
|
self.axes.imshow(dataset.asarray(), interpolation='nearest')
|
||||||
self.axes.axis('tight')
|
self.axes.axis('tight')
|
||||||
|
self._mappable = self.axes.images[0]
|
||||||
|
|
||||||
# Disable selection modes
|
# Disable selection modes
|
||||||
self._toolbar.freeze_button.set_sensitive(False)
|
self._toolbar.freeze_button.set_sensitive(False)
|
||||||
|
@ -632,6 +665,7 @@ class NetworkPlot(Plot):
|
||||||
c=self._nodecolor,
|
c=self._nodecolor,
|
||||||
linewidth=lw,
|
linewidth=lw,
|
||||||
zorder=3)
|
zorder=3)
|
||||||
|
self._mappable = node_collection
|
||||||
# selected nodes is a transparent graph that adjust node-edge visibility
|
# selected nodes is a transparent graph that adjust node-edge visibility
|
||||||
# according to the current selection needed to get get the selected
|
# according to the current selection needed to get get the selected
|
||||||
# nodes 'on top' as zorder may not be defined individually
|
# nodes 'on top' as zorder may not be defined individually
|
||||||
|
|
Reference in New Issue