Commit dac14a84 authored by Jesse Heckman's avatar Jesse Heckman

new moving sound update and draft plots

parent 9860ff9c
......@@ -49,21 +49,25 @@ function draft(obj)
axis(obj(iAx).pva.axis);
hold on;
% Set colors
nCol = 1;
if ~obj(iObj).pva.continious
nCol = length(unique(obj(iObj).pva.color));
end
% Plot data
% FIX COLOR REPEAT ONLY FOR COLOR SPLITTING DATA
colors = pb_selectcolor(nCol,obj(iAx).pva.def);
uD = unique(obj(iAx).pva.color);
for iCol = 1:nCol
d = obj(iAx).pva;
d.ind = d.color == uD(iCol);
d.color = colors(iCol,:);
for iDP = 1:length(obj(iObj).dplot)
obj(iObj).dplot{iDP}(obj,d);
end
end
% Plot all graphs
for iDP = 1:length(obj(iObj).dplot)
d = obj(iAx).pva;
obj(iObj).dplot{iDP}(obj,d);
end
% Set labels
......
function fit_ellipse(obj,varargin)
% PB_DRAFT>FIT_ELLIPSE
%
% OBJ.PLOT_VLINE(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
p.type = pb_keyval('type',v,'dot');
p.alpha = pb_keyval('alpha',v,1); %% crashes if you change the alpha to below 1?
p.marker = pb_keyval('marker',v,'o');
p.markersz = pb_keyval('markersz',v,3);
p.linestyle = pb_keyval('linestyle',v,'-');
p.linewidth = pb_keyval('linestyle',v,2);
p.fcol = pb_keyval('facecolor',v,'fill');
p.col = pb_keyval('color',v,'k');
p.ncol = pb_keyval('ncol',v,unique(obj.pva.color));
for iCol = 1:length(p.ncol)
obj.dplot = vertcat(obj.dplot,{@(dobj,data)ellipsefit(dobj,data,p,p.ncol(iCol))});
end
obj.results.ellipse_handle = {};
end
function h = ellipsefit(~,data,p,colorindex)
% makes a vertical
sel = data.color == colorindex;
x = data.x(sel);
y = data.y(sel);
color = pb_selectcolor(length(p.ncol),data.def);
[Mu,SD,Phi,~,~] = pb_ellipse(x,y);
h = pb_ellipseplot(Mu,SD,Phi,'Color',color(colorindex,:));
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -56,7 +56,7 @@ classdef pb_draft < matlab.mixin.Copyable
plot_hline(obj,varargin); % plot horizontal lines
plot_vline(obj,varargin); % plot vertical lines
plot_dline(obj,varargin); % plot diagonal lines
plot_bubble(obj,varargin);
plot_bubble(obj,varargin); % plot bubblr histoplot
stat_regres(obj,varargin); % transform regression
stat_probit(obj,varargin); % transform probit
......
......@@ -13,17 +13,18 @@ function plot_bubble(obj,varargin)
p.YW = pb_keyval('Ywidth',v);
p.BS = pb_keyval('binsize',v);
p.def = pb_keyval('def',v,5);
p.marker = pb_keyval('marker',v,'o');
obj.dplot = vertcat(obj.dplot,{@(dobj,data)bubble_plot(dobj,data,p)});
obj.results.bubbleplot_handle = {};
end
function h = bubble_plot(~,data,p)
% Bubbleplot
%% Bubbleplot
% Select binsizes
if isempty(p.XW); [~,~,p.XW,~] = pb_binsize(data.x); end
if isempty(p.YW); [~,~,p.YW,~] = pb_binsize(data.y); end
if isempty(p.XW); [~,~,p.XW,~] = pb_binsize(data.x); p.XW = p.XW*3; end
if isempty(p.YW); [~,~,p.YW,~] = pb_binsize(data.y); p.YW = p.YW*3; end
if ~isempty(p.BS); p.XW = p.BS; p.YW = p.BS; end
% Hist
......@@ -37,7 +38,7 @@ function h = bubble_plot(~,data,p)
TOT = NaN(size(UX));
for ii = 1:length(uX)
sel = X == uX(ii);
sel = X == uX(ii);
r = Y(sel);
N = hist(r,x);
if isscalar(x)
......@@ -46,42 +47,29 @@ function h = bubble_plot(~,data,p)
TOT(:,ii) = N;
end
%% Normalize
TOT = log10(TOT+1);
mxTOT = nanmax(nanmax(TOT));
mnTOT = nanmin(nanmin(TOT));
TOT = (TOT-mnTOT)./(mxTOT-mnTOT);
% Normalize
TOT = log10(TOT+1);
maxima(1) = nanmax(nanmax(TOT));
maxima(2) = nanmin(nanmin(TOT));
TOT = (TOT-maxima(2))./(maxima(1)-maxima(2));
%% Plot
M = TOT(:);
x = UX(:);
y = UY(:);
% Plot
M = TOT(:);
x = UX(:);
y = UY(:);
sel = M>0;
M = M(sel);
x = x(sel);
y = y(sel);
sel = M>0;
M = M(sel);
x = x(sel);
y = y(sel);
SZ = ceil(100*M);
[~,~,idx] = unique(M);
col = statcolor(max(idx),[],[],[],'def',p.def);
C = col(idx,:);
h = plot(x,...
y, ...
'Marker', p.marker, ...
'LineStyle',p.ls, ...
'Color',C);
'MarkerFaceColor',C...
'MarkerSize', p.markersz);
h = scatter(x,y,SZ,C,'filled');
end
'Color', data.color, ...
switchpar, ...
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
......
......@@ -8,32 +8,48 @@ function plot_rawdata(obj,varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
p.type = pb_keyval('type',v,'line');
p.type = pb_keyval('type',v,'dot');
p.alpha = pb_keyval('alpha',v,1); %% crashes if you change the alpha to below 1?
p.marker = pb_keyval('marker',v,'o');
p.markersz = pb_keyval('markersz',v,3);
p.ls = pb_keyval('linestyle',v,'none');
p.linestyle = pb_keyval('linestyle',v,'-');
p.linewidth = pb_keyval('linestyle',v,2);
p.fcol = pb_keyval('facecolor',v,'fill');
p.col = pb_keyval('color',v,'k');
obj.dplot = vertcat(obj.dplot,{@(dobj,data)rawdata(dobj,data,p)});
p.ncol = pb_keyval('ncol',v,unique(obj.pva.color));
for iCol = 1:length(p.ncol)
obj.dplot = vertcat(obj.dplot,{@(dobj,data)rawdata(dobj,data,p,p.ncol(iCol))});
end
obj.results.rawdata_handle = {};
end
function h = rawdata(~,data,p)
function h = rawdata(~,data,p,colorindex)
% Plots rawdata
%% MAKE SELECTION FOR COLOR!
sel = data.color == colorindex;
x = data.x(sel);
y = data.y(sel);
color = pb_selectcolor(length(p.ncol),data.def);
switch p.type
case 'dot'
sz = p.sz;
h = scatter(data.x,data.y,ceil(p.markersz/2.5),data.color,'filled','MarkerFaceAlpha',p.alpha); %% crashes if you change the alpha to below 1?
case 'line'
if strcmp(p.fcol,'fill'); switchpar = data.color; else; switchpar = 'none'; end
h = plot(data.x(data.ind), ...
data.y(data.ind), ...
h = plot(x, ...
y, ...
'Color', data.color, ...
'Marker', p.marker, ...
'LineStyle',p.ls, ...
'LineStyle',p.linestyle, ...
'LineWidth', p.linewidth);
case 'dot'
if strcmp(p.fcol,'fill'); switchpar = color(colorindex,:); else; switchpar = 'none'; end
h = plot(x, ...
y, ...
'Color', color(colorindex,:), ...
'Marker', p.marker, ...
'LineStyle','none', ...
'MarkerFaceColor',switchpar, ...
'MarkerSize', p.markersz);
otherwise
......
......@@ -21,6 +21,8 @@ function parse_va(obj,varargin)
pva.axis = pb_keyval('axis',v,'square');
pva.subtitle = pb_keyval('subtitle',v);
pva.colscheme = pb_selectcolor(length(unique(pva.color)),pva.def);
obj.labels.xlab = pb_keyval('xlab',v,'');
obj.labels.ylab = pb_keyval('ylab',v,'');
......
function set_grid(obj,varargin)
% PB_DRAFT>SET_GRID
%
% SET_TITLE(obj,title,varargin) ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function set_title(obj,title,varargin)
% WRITETITLE()
% PB_DRAFT>SET_GRID
%
% WRITETITLE() ...
% SET_TITLE(obj,title,varargin) sets title for pb_draft object
%
% See also ...
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
......
......@@ -3,22 +3,24 @@ pb_clean;
load('exD_saccade');
cfn = pb_newfig(0,'size',[0 0 17 17],'resize','off');
colormap copper;
%%
% construct
for i = 1:2
for j = 1:2
d(j,i) = pb_draft('x',Saccades.GazeLatency*1000,'y',Saccades.HeadLatency*1000,'color',Saccades.Modality,'subtitle',['s00' num2str(i)]);
d(j,i) = pb_draft('x',Saccades.GazeLatency*1000,'y',Saccades.HeadLatency*1000,'color',Saccades.Modality,'subtitle',['s00' num2str(j)]);
d(j,i).set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
if ~iseven(j)
d(j,i).plot_rawdata('marker','o','facecolor','none');
d(j,i).plot_rawdata;
else
d(j,i).plot_bubble('binsize',50);
d(j,i).plot_bubble;
d(j,i).fit_ellipse;
end
d(j,i).plot_dline
%d(j,i).fit_ellipse;
d(j,i).plot_dline;
d(j,i).plot_vline('type','mode');
d(j,i).plot_hline('type','mode');
end
end
......
No preview for this file type
function h = pb_ellipseplot(Mu,SD,Phi,varargin)
% PB_ELLIPSEPLOT
%
% PB_ELLIPSEPLOT(Mu,SD,Phi,varargin)
%
% See also PB_ELLIPSEP, PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
col = pb_keyval('color',v,'k');
alpha = pb_keyval('alpha',v,.33);
ls = pb_keyval('linestyle',v,'--');
SD = pb_keyval('sd',v,SD*2);
disp = pb_keyval('disp',v,true);
regcol = pb_keyval('regcol',v,col);
hs = ishold(gca);
hold on;
Xo = Mu(1);
Yo = Mu(2);
L = SD(1);
S = SD(2);
DTR = pi/180;
Phi = Phi*DTR;
% Ellipse
wt = (0:.1:360) .* DTR;
X = Xo + L*cos(Phi)*cos(wt) - S*sin(Phi)*sin(wt);
Y = Yo + L*sin(Phi)*cos(wt) + S*cos(Phi)*sin(wt);
% Graphics
h = patch(X,Y,col);
set(h(1),...
'EdgeColor',col,...
'LineWidth',1,...
'LineStyle',ls,...
'FaceAlpha',alpha);
if disp
h(2) = pb_regplot(X,Y,'data',false,'color',col);
end
if ~hs; hold on; end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [MU,SD,A,x,y] = pb_ellipse(x,y,varargin)
% PB_ELLIPSE
%
% PB_ELLIPSE(x,y,varargin)
%
% See also PB_ELLIPSEPLOT, PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
out = pb_keyval('outlier',v,[]);
% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
% Delete response >3SD
if ~isempty(out)
SD = sqrt(diag(Deig)); % diagonal Deig = variance in the 2 main axes
xmu = mean(x);
ymu = mean(y);
[Xr,Yr] = rotate2d(x,y,-A);
seld = abs(Xr-mean(Xr))<out*SD(2) & abs(Yr-mean(Yr))<out*SD(1);
x = x(seld);
y = y(seld);
% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
end
% diagonal Deig = variance in the 2 main axes
SD = sqrt(diag(Deig));
xmu = mean(x);
ymu = mean(y);
MU = [xmu ymu];
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function h = pb_ellipseplot(Mu,SD,Phi,varargin)
% PB_ELLIPSEPLOT
%
% PB_ELLIPSEPLOT(Mu,SD,Phi,varargin)
%
% See also PB_ELLIPSEP, PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
col = pb_keyval('color',v,'k');
alpha = pb_keyval('alpha',v,.33);
ls = pb_keyval('linestyle',v,'--');
SD = pb_keyval('sd',v,SD*2);
disp = pb_keyval('disp',v,false);
regcol = pb_keyval('regcol',v,col);
hs = ishold(gca);
hold on;
Xo = Mu(1);
Yo = Mu(2);
L = SD(1);
S = SD(2);
DTR = pi/180;
Phi = Phi*DTR;
% Ellipse
wt = (0:.1:360) .* DTR;
X = Xo + L*cos(Phi)*cos(wt) - S*sin(Phi)*sin(wt);
Y = Yo + L*sin(Phi)*cos(wt) + S*cos(Phi)*sin(wt);
% Graphics
h = patch(X,Y,col);
set(h(1),...
'EdgeColor',col,...
'LineWidth',1,...
'LineStyle',ls,...
'FaceAlpha',alpha);
if disp; h(2) = pb_regplot(X,Y,'data',false,'color',col); end %% REGRESSION DOES NOT MATCH ANGLE OF ELLIPSE
if ~hs; hold on; end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_ellipsoid()
function [MU,SD,A,x,y] = ellipse(x,y,varargin)
% PB_ELLIPSOID()
%
% PB_ELLIPSOID() ...
......@@ -7,40 +7,42 @@ function pb_ellipsoid()
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Initialization
out = keyval('outlier',varargin);
splot = pb_keyval('show',varargin,true);
if isempty(out)
out = []; % (Hz)
end
%% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
%% Delete response >3SD
if ~isempty(out)
SD = sqrt(diag(Deig)); % diagonal Deig = variance in the 2 main axes
xmu = mean(x);
ymu = mean(y);
[Xr,Yr] = rotate2d(x,y,-A);
seld = abs(Xr-mean(Xr))<out*SD(2) & abs(Yr-mean(Yr))<out*SD(1);
x = x(seld);
y = y(seld);
%% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
end
%% diagonal Deig = variance in the 2 main axes
SD = sqrt(diag(Deig));
xmu = mean(x);
ymu = mean(y);
MU = [xmu ymu];
%% Initialization
out = keyval('outlier',varargin);
if isempty(out)
out = []; % (Hz)
end
%% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
%% Delete response >3SD
if ~isempty(out)
SD = sqrt(diag(Deig)); % diagonal Deig = variance in the 2 main axes
xmu = mean(x);
ymu = mean(y);
[Xr,Yr] = rotate2d(x,y,-A);
seld = abs(Xr-mean(Xr))<out*SD(2) & abs(Yr-mean(Yr))<out*SD(1);
x = x(seld);
y = y(seld);
%% Eigen-values for covariance-matrix
[Veig,Deig] = eig(cov(x,y)); % Veig gives main axes
A = bf_rad2deg(atan2(Veig(2),Veig(1))); % angle
end
%% diagonal Deig = variance in the 2 main axes
SD = sqrt(diag(Deig));
xmu = mean(x);
ymu = mean(y);
MU = [xmu ymu];
end
......
function [h,b,r] = pb_regplot(X,Y)
function [h,b,r] = pb_regplot(X,Y,varargin)
% PB_REGPLOT()
%
% plots data, and linear regression.
......@@ -7,39 +7,38 @@ function [h,b,r] = pb_regplot(X,Y)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Initialization
X = X(:)';
Y = Y(:)';
mrkr = 'o';
%% Initialization
%% Regression
b = regstats(Y,X,'linear','beta');
b = b.beta;
gain = b(2);
bias = b(1);
r = corrcoef(X,Y); r = r(2);
v = varargin;
marker = pb_keyval('marker',v,'o');
data = pb_keyval('data',v,true);
text = pb_keyval('text',v,false);
color = pb_keyval('color',v,'k');
linestyle = pb_keyval('linestyle',v,'--');
linewidth = pb_keyval('linewidth',v,2);
X = X(:)';
Y = Y(:)';
hs = ishold(gca);
hold on;
%% Regression
b = regstats(Y,X,'linear','beta');
b = b.beta;
gain = b(2);
bias = b(1);
r = corrcoef(X,Y); r = r(2);
%% Text
if bias>0
linstr = ['Y = ' num2str(gain,2) 'X + ' num2str(bias,2) ];
elseif bias<=0
linstr = ['Y = ' num2str(gain,2) 'X - ' num2str(abs(bias),2) ];
end
corrstr = ['r^2 = ' sprintf('%0.3f',r^2)];
%% Graphics
h = plot(X, Y, ['k' mrkr]);
hold on
lsline;
axis square;
box off;
text(range(1)+10,range(4)-20,corrstr,'HorizontalAlignment','left')
axxes = axis;
plot(axxes([1 2]),gain*axxes([1 2])+bias,'k-','LineWidth',2);
%% Graphics
h = gobjects(0);
if data; h(1) = plot(X, Y, ['k' marker]); end
axxes = axis;
h(end+1) = plot(axxes([1 2]),gain*axxes([1 2])+bias,'Color',color,'LineStyle',linestyle,'LineWidth',linewidth);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment