Added correlation plot and moved colorbar to plots
This commit is contained in:
parent
90bb25eb55
commit
34ae426c86
|
@ -10,7 +10,8 @@ import gtk
|
|||
import fluents
|
||||
from fluents import plots
|
||||
import scipy
|
||||
from scipy import dot,sum,diag,arange,log,mean,newaxis,sqrt
|
||||
from scipy import dot,sum,diag,arange,log,mean,newaxis,sqrt,apply_along_axis
|
||||
|
||||
|
||||
class BlmScatterPlot(plots.ScatterPlot):
|
||||
"""Scatter plot used for scores and loadings in bilinear models."""
|
||||
|
@ -24,7 +25,6 @@ class BlmScatterPlot(plots.ScatterPlot):
|
|||
absi= ordi = 0
|
||||
self._absi = absi
|
||||
self._ordi = ordi
|
||||
self._colorbar = None
|
||||
self._cmap = cm.jet
|
||||
dataset_1 = model.as_dataset(part_name)
|
||||
id_dim = dataset_1.get_dim_name(0)
|
||||
|
@ -38,11 +38,9 @@ class BlmScatterPlot(plots.ScatterPlot):
|
|||
|
||||
plots.ScatterPlot.__init__(self, dataset_1, dataset_1, id_dim, sel_dim, id_1, id_2 ,c=col ,s=40 , name=title)
|
||||
|
||||
self.sc.set_cmap(self._cmap)
|
||||
self._mappable.set_cmap(self._cmap)
|
||||
self.sc = self._mappable
|
||||
self.add_pc_spin_buttons(self._T.shape[1], absi, ordi)
|
||||
self._key_press = self.canvas.mpl_connect(
|
||||
'key_press_event', self._on_key_press)
|
||||
|
||||
|
||||
def _update_color_from_dataset(self, data):
|
||||
"""Overriding scatter for testing of colormaps.
|
||||
|
@ -77,10 +75,6 @@ class BlmScatterPlot(plots.ScatterPlot):
|
|||
self.sc.update_scalarmappable() #sets facecolors from array
|
||||
self.canvas.draw()
|
||||
|
||||
def _on_key_press(self, event):
|
||||
if event.key=='c':
|
||||
self.toggle_colorbar()
|
||||
|
||||
def set_facecolor(self, colors):
|
||||
"""Set patch facecolors.
|
||||
"""
|
||||
|
@ -93,25 +87,6 @@ class BlmScatterPlot(plots.ScatterPlot):
|
|||
def set_sizes(self, sizes):
|
||||
"""Set patch sizes."""
|
||||
pass
|
||||
|
||||
def toggle_colorbar(self):
|
||||
if self._colorbar==None:
|
||||
if self.sc._A!=None: # we need colormapping
|
||||
# get axes original position
|
||||
self._ax_last_pos = self.axes.get_position()
|
||||
self._colorbar = self.fig.colorbar(self.sc)
|
||||
self._colorbar.draw_all()
|
||||
self.canvas.draw()
|
||||
else:
|
||||
# remove colorbar
|
||||
# remove, axes, observers, colorbar instance, and restore viewlims
|
||||
cb, ax = self.sc.colorbar
|
||||
self.fig.delaxes(ax)
|
||||
self.sc.observers = [obs for obs in self.sc.observers if obs !=self._colorbar]
|
||||
self._colorbar = None
|
||||
self.sc.colorbar = None
|
||||
self.axes.set_position(self._ax_last_pos)
|
||||
self.canvas.draw()
|
||||
|
||||
def add_pc_spin_buttons(self, amax, absi, ordi):
|
||||
sb_a = gtk.SpinButton(climb_rate=1)
|
||||
|
@ -210,6 +185,12 @@ class PlsLoadingPlot(BlmScatterPlot):
|
|||
BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='P', color_by='w_tsq')
|
||||
|
||||
|
||||
class PlsCorrelationLoadingPlot(BlmScatterPlot):
|
||||
def __init__(self, model, absi=0, ordi=1):
|
||||
title = "Pls correlation loadings (%s)" %model._dataset['X'].get_name()
|
||||
BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='CP')
|
||||
|
||||
|
||||
class LineViewXc(plots.LineViewPlot):
|
||||
"""A line view of centered raw data
|
||||
"""
|
||||
|
@ -278,8 +259,21 @@ class PredictionErrorPlot(plots.Plot):
|
|||
|
||||
def set_current_selection(self, selection):
|
||||
pass
|
||||
|
||||
|
||||
class TRBiplot(plots.ScatterPlot):
|
||||
def __init__(self, model, absi=0, ordi=1):
|
||||
title = "Target rotation biplot(%s)" %model._dataset['X'].get_name()
|
||||
BlmScatterPlot.__init__(self, title, model, absi, ordi, 'B')
|
||||
B = model.model.get('B')
|
||||
# normalize B
|
||||
Bnorm = scipy.apply_along_axis(scipy.linalg.norm, 1, B)
|
||||
x = model._dataset['X'].copy()
|
||||
Xc = x._array - mean(x._array,0)[newaxis]
|
||||
w_rot = B/Bnorm
|
||||
t_rot = dot(Xc, w_rot)
|
||||
|
||||
|
||||
|
||||
class InfluencePlot(plots.ScatterPlot):
|
||||
"""
|
||||
"""
|
||||
|
|
Reference in New Issue