Added colorbar shortcut
This commit is contained in:
parent
fefaffb2e3
commit
31ac569c3e
@ -39,15 +39,18 @@ class Plot(view.View):
|
||||
def _init_mpl(self):
|
||||
# init matplotlib related stuff
|
||||
self._background = None
|
||||
self._colorbar = None
|
||||
self._use_blit = False
|
||||
self.fig = Figure()
|
||||
self.canvas = FigureCanvasGTKAgg(self.fig)
|
||||
self.axes = self.fig.gca()
|
||||
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.add(self.canvas)
|
||||
self.canvas.show()
|
||||
|
||||
|
||||
def set_frozen(self, frozen):
|
||||
"""A frozen plot will not be updated when the current
|
||||
selection is changed."""
|
||||
@ -127,6 +130,34 @@ class Plot(view.View):
|
||||
if not ids : return []
|
||||
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):
|
||||
"""Line view plot with percentiles.
|
||||
@ -170,7 +201,7 @@ class LineViewPlot(Plot):
|
||||
def _set_background(self, ax):
|
||||
"""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
|
||||
# settings
|
||||
patch_color = 'b' #blue
|
||||
@ -187,7 +218,7 @@ class LineViewPlot(Plot):
|
||||
verts_0 = [] #100,0
|
||||
verts_1 = [] # 90,10
|
||||
verts_2 = [] # 75,25
|
||||
med = []
|
||||
med = []
|
||||
# add top vertices the low vertices (do i need an order?)#background
|
||||
for i in xax:
|
||||
prct = prctile(self._data.take([i], self.minor_axis), percentiles)
|
||||
@ -368,6 +399,7 @@ class ScatterPlot(Plot):
|
||||
self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data,
|
||||
s=self.s, c=self.c, linewidth=lw,
|
||||
zorder=3, **self.kw)
|
||||
self._mappable = self.sc
|
||||
self.axes.axhline(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,
|
||||
@ -470,6 +502,7 @@ class ImagePlot(Plot):
|
||||
self.axes.grid(False)
|
||||
self.axes.imshow(dataset.asarray(), interpolation='nearest')
|
||||
self.axes.axis('tight')
|
||||
self._mappable = self.axes.images[0]
|
||||
|
||||
# Disable selection modes
|
||||
self._toolbar.freeze_button.set_sensitive(False)
|
||||
@ -632,6 +665,7 @@ class NetworkPlot(Plot):
|
||||
c=self._nodecolor,
|
||||
linewidth=lw,
|
||||
zorder=3)
|
||||
self._mappable = node_collection
|
||||
# selected nodes is a transparent graph that adjust node-edge visibility
|
||||
# according to the current selection needed to get get the selected
|
||||
# nodes 'on top' as zorder may not be defined individually
|
||||
|
Reference in New Issue
Block a user