Commit 37ec3c7d authored by Jesse Heckman's avatar Jesse Heckman

major update DRAFT: set axes, set legends, set labels.

parent 46f4451e
......@@ -47,13 +47,13 @@ function draft(obj)
nCmp = length(unique(obj(1).pva.axcomp.feature));
if min(objsz) > 1; nCmp = 1; end
cmpsz = [1 1];
nObj = numel(obj) * nCmp;
cmpsz = [1 1];
[~,cmpInd] = max(cmpsz);
cmpsz(cmpInd) = nCmp;
cmpsz = fliplr(cmpsz);
obj(1).h_ax_plot.sz = cmpsz .* size(obj);
%% Create Plots
% Draft each subplot
......@@ -63,8 +63,8 @@ function draft(obj)
cObj = (iObj-1)*nCmp + iCmp;
% Make Axes
Ax = pb_invidx([objsz(1)*cmpsz(1), objsz(2)*cmpsz(2)],cObj); % reverse get axes index
Ax2Obj = pb_invidx([objsz(1), objsz(2)],iObj); % reverse get object index
Ax = pb_invidx(objsz.*cmpsz,cObj); % reverse get axes index
Ax2Obj = pb_invidx(objsz,iObj); % reverse get object index
ax(Ax) = subplot(objsz(1)*cmpsz(1),objsz(2)*cmpsz(2),cObj); % make axis
if obj(iObj).pva.subtitle; title(obj(Ax2Obj).pva.subtitle); end
......@@ -101,7 +101,10 @@ function draft(obj)
% TO DO:
% 1. Scale and move axis to make graph nice, pleasing and non-overlapping
obj.make_axes(ax);
obj.make_legend;
obj.make_suplabel;
end
......
......@@ -49,27 +49,32 @@ classdef pb_draft < matlab.mixin.Copyable
end
% Set functions
set_title(obj,title,varargin); % set title
set_legend(obj,varargin); % set legend
set_title(obj,title,varargin); % set title
set_labels(obj,varargin); % set labels
set_grid(obj,varargin); % set grid
set_axcomp(obj,feature,varargin); % set comparision axe
set_axcomp(obj,feature,varargin); % set comparision axe
set_legend(obj,varargin); % set legend
% Plot functions
plot_rawdata(obj,varargin); % plot the rawdata
plot_bubble(obj,varargin); % plot bubble histoplot
plot_bubble(obj,varargin); % make bubbleplot
plot_hline(obj,varargin); % plot horizontal lines
plot_vline(obj,varargin); % plot vertical lines
plot_dline(obj,varargin); % plot diagonal lines
plot_dline(obj,varargin); % plot diagonal lines
% plot_polar(obj,varargin); % make polarplot
% Statistical functions
stat_regres(obj,varargin); % transform regression // NOT YET DONE
stat_probit(obj,varargin); % transform probit // MADE NOT FINISHED
stat_probit(obj,varargin); % make probitplot
% stat_boxplot(obj,varargin); % make boxplot
% stat_regres(obj,varargin); % plot regression
% stat_shade(obj,varargin); % plot shaded area
% Fitting functions
fit_ellipse(obj,varargin); % make ellipse fit
fit_sigmoid(obj,varargin); % make sigmoidal fit
fit_polyn(obj,varargin); % make polynomial fit
% fit_sigmoid(obj,varargin); % make sigmoidal fit
% fit_polyn(obj,varargin); % make polynomial fit
% fit_exp(obj,varargin); % make exponential fit
% fit_custom(obj,varargin); % make custom fit
% Core functions
draft(obj); % draw figure
......
function make_axes(obj,ax,varargin)
% PB_DRAFT>MAKE_AXES
%
% OBJ.SET_LEGEND(varargin) rescale, size and store axes handles..
% OBJ.MAKE_AXES(varargin) rescale, size and store axes handles..
%
% See also PB_DRAFT
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
linkaxes(ax,'xy');
positions = zeros(length(ax),4);
positions = zeros(length(ax),4);
nAx = length(ax);
for iAx = 1:length(ax)
for iAx = 1:nAx
sz = obj(1).h_ax_plot.sz;
cAx = pb_invidx(sz,iAx); % align axes and objects
ax(cAx);
% Scale for legend
if obj(1).h_ax_legend.bool
scale = [0.8 1];
szfl = fliplr(sz);
[xN,yN] = pb_mod(iAx,sz(2)); if xN == 0; xN = sz(2); end
N = [xN,yN+1];
ax(cAx).OuterPosition(3:4) = ax(cAx).OuterPosition(3:4)*scale(1);
for iDir = 1:2
width = ax(cAx).OuterPosition(2+iDir);
spacing(iDir) = (scale(iDir)-(width*szfl(iDir)))/(szfl(iDir)+1);
if iDir == 1; ax(cAx).OuterPosition(1) = (N(1)-1)*width + N(1)*spacing(iDir); end
if iDir == 2
if spacing(2)>spacing(1)*1.5
spacing(2) = spacing(1)*1.5;
end
margin = (1-(sz(1)*width + (sz(1)-1)*spacing(2)))/2;
ax(cAx).OuterPosition(2) = 1-margin-(N(2)*width) - (N(2)-1)*spacing(iDir);
end
end
end
axis(ax(iAx));
% Set Limits
if obj(1).pva.setAxes
......@@ -21,7 +50,7 @@ function make_axes(obj,ax,varargin)
end
% Set Grids
setAx = ax(iAx);
setAx = ax(cAx);
if obj(1).grid.bool
f = obj(1).grid.features;
setAx.Box = f.Box;
......@@ -37,7 +66,7 @@ function make_axes(obj,ax,varargin)
setAx.YDir = f.YDir;
setAx.LineWidth = f.LineWidth;
end
positions(iAx,:) = ax(iAx).Position(:);
positions(cAx,:) = ax(cAx).Position(:);
end
% Set Label Positions
......
function make_legend(obj,varargin)
% PB_DRAFT>MAKE_LEGEND
%
% OBJ.MAKE_LEGEND(varargin) rescale, size and store axes handles..
%
% See also PB_DRAFT
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
lgnd = obj(1).h_ax_legend;
if lgnd.bool
h = axes('Units','Normal','Position',[.8 .3 .15 .4],'Visible','off','tag','legend');
hold on;
t = text(0,0.5,'LEGEND1','Visible','on');
p = plot(0,0.5,'o','Visible','on');
xlim = [0 1];
ylim = [0 1];
%[n,m] = readlegend(lgnd.features.entries,lgnd.features.fontsize);
end
end
function [n,m] = readlegend(entries,fontsize)
% returns the size of the legend
if isempty(entries)
n = 0; m = 0;
return
end
n = length(entries);
n = (n+1)*0.04;
z = axes();
set(z,units,'centimeters');
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -52,6 +52,9 @@ function parse_va(obj,varargin)
obj.labels.ylab = pb_keyval('ylab',v,'');
obj.grid.bool = false;
% Set legend
obj(1).h_ax_legend.bool = false;
% Check data continuity for colouring
pva.continious = false;
if length(unique(pva.color)) > 5 && ~prod(floor(pva.color) == pva.color)
......
......@@ -7,7 +7,15 @@ function set_legend(obj,varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
f.marker = pb_keyval('Marker',v,'o');
f.entries = pb_keyval('Entries',v,[]);
f.fontsize = pb_keyval('Fontsize',v,9);
f.fontname = pb_keyval('Fontname',v,'Helvetica');
obj(1).h_ax_legend.bool = true;
obj(1).h_ax_legend.handles = {};
obj(1).h_ax_legend.features = f;
end
......
......@@ -14,7 +14,6 @@ function stat_probit(obj,varargin)
p.ncol = pb_keyval('ncol',v,unique(obj.pva.color));
p.visibility = pb_keyval('visibility',v,'off');
obj.plot_hline;
for iCol = 1:length(p.ncol)
obj.dplot = vertcat(obj.dplot,{@(dobj,data)probit_stat(dobj,data,p,p.ncol(iCol))});
end
......@@ -29,55 +28,12 @@ function h = probit_stat(~,data,p,colorindex)
sel = data.color == colorindex;
y = data.y(sel);
if isempty(y); disp('No entry for y-data found!'); return; end
gcol = pb_selectcolor(length(p.ncol),5);
if isempty(y); return; end
gcol = pb_selectcolor(3,5);
color = pb_selectcolor(length(p.ncol),data.def);
color = color(colorindex,:);
%% Rawdata
% Plot rawdata
iRT = 1/(y);
x = -1./sort(y);
n = numel(iRT);
y = probitscale((1:n)./n);
%h(1) = plot(x,y,'Color',gcol(colorindex,:),'Marker','o','MarkerFaceColor',gcol(colorindex,:),'LineStyle','None');
%% Quantiles & regression
p = [1,2,5,10,25,50,75,90 95 98 99]/100;
xtick = sort(-1./(150+[0 pb_oct2bw(50,-1:5)]));
prob = sqrt(2) * erfinv(2*p - 1);
q = -1./quantile(y,p);
b = regstats(prob,q);
rl = regline(b.beta,'k--');
h = plot(q,prob,'Color',color,'Marker','o','MarkerFaceColor',color,'LineStyle','None');
%set(h(1),'Tag','Rawdata');
set(h,'Tag','Probit model');
set(rl,'Tag','Graphical aid: regline');
%% Design
% Set Axis for probit
% TODO: --> FIGURE OUT WHY THE FUCK THERE IS NO VISUAL PROBIT MODEL?
%
% set(gca,'XTick',xtick,'XTickLabel',-1./xtick);
% set(gca,'YTick',prob,'YTickLabel',p*100);
% xlim([min(xtick) max(xtick)]);
% ylim([probit(0.1/100) probit(99.9/100)]);
% xlabel('Reaction time (ms)');
% ylabel('Cumulative probability');
% axis square;
% box off
end
function chi = probitscale(cdf)
% creates a probitscale
chi = sqrt(2) * erfinv(2*cdf - 1);
h = pb_probit(y,'color',color,'gcolor',gcol(1,:));
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -4,38 +4,40 @@
pb_clean; % Empty
load('exD_saccade'); % load example data
cfn = 0; % Initialize current figure number
run = 3; % Set # of blocks to run
run = 1; % Set # of blocks to run
%% Block 1:
% Make figure 1: Plot data
if run>cfn
% Make figure & draft-obj
cfn = pb_newfig(cfn,'size',[0 0 17 17],'ws','Docked');
d = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
% Plots
d.plot_rawdata
d.plot_vline('type','mode');
d.plot_hline('type','mode');
% Layout
d.set_title('Saccade Latencies');
d.set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
d.set_grid;
% Build
d.draft
%d.print
end
% if run>cfn
% % Make figure & draft-obj
% cfn = pb_newfig(cfn,'size',[0 0 17 17],'resize','off');
% d = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
%
% % Plots
% d.plot_rawdata
% d.plot_vline('type','mode');
% d.plot_hline('type','mode');
%
% % Layout
% d.set_title('Saccade Latencies');
% d.set_labels('x','Gaze Latency (ms)','y','Head Latency (ms)');
% d.set_grid;
% d.set_legend('Entries',{'Audio','Visual','Audiovisual'});
%
% % Build
% d.draft
% %d.print('disp',true);
% end
%% Block 2:
% Make figure 2: Plot rawdata + bubbleplot
if run>cfn
tic
% Make figure
cfn = pb_newfig(cfn,'size',[0 0 17 12],'ws','Docked');
cfn = pb_newfig(cfn,'size',[0 0 17 12],'resize','off');
for iR = 1:2
% Build draft-objs
d(iR,1) = pb_draft('x',Saccades.GazeLatency,'y',Saccades.HeadLatency,'color',Saccades.Modality);
......@@ -57,26 +59,45 @@ if run>cfn
d.set_title('Saccade Latencies');
d.set_axcomp(Saccades.Subject);
d.set_grid;
d.set_legend('Entries',{'Audio','Visual','Audiovisual'});
% Build
d.draft;
%d.print
d.print('disp',true);
toc
end
%% Block 3:
% Make figure 3: Probitplot
if run>cfn
% Make figure & draft-obj
cfn = pb_newfig(cfn,'size',[0 0 17 17],'ws','Docked');
d = pb_draft('y',Saccades.HeadLatency); %,'color',Saccades.Modality);
cfn = pb_newfig(cfn,'size',[0 0 17 10],'resize','off');
d = pb_draft('y',Saccades.HeadLatency,'color',Saccades.Modality);
d.stat_probit;
d.set_axcomp(Saccades.Modality);
d.set_title('Probit plot');
d.set_labels('x','Reaction Times (ms)','y','Cumulative Probability');
d.set_grid;
% Build
d.draft;
%d.print
d.print('disp',true);
end
%% Block 4:
% Make figure 4: Probitplot
if run>cfn
% Make figure & draft-obj
cfn = pb_newfig(cfn,'size',[0 0 17 10],'resize','off');
d = pb_draft('y',Saccades.HeadLatency,'color',Saccades.Modality);
% Build
d.draft;
d.print('disp',true);
end
......@@ -22,8 +22,7 @@ function [cfn,f] = pb_newfig(cfn, varargin)
set(f,'Units',units);
set(f,'Resize',rsz)
if ~strcmp(ws,'Docked');set(f, 'Position',sz); end
if ~strcmp(ws,'Docked'); set(f, 'Position',sz); end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
function [modulo,div] = pb_mod(a,b)
% PB_MOD
%
% PB_MOD(a,b) returns the modulo and the number of full divisions.
%
% See also MOD, REM
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
modulo = mod(a,b);
div = floor(a/b);
if div == a/b; div = div-1; end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -17,40 +17,34 @@ function [h,D] = pb_probit(D, varargin)
ho = pb_keyval('ho',varargin,ishold);
fig = pb_keyval('fig',varargin, gcf);
ax = pb_keyval('ax',varargin, gca);
col = pb_keyval('color',varargin,[0 0 0]);
gcol = pb_keyval('gcolor',varargin,[.66 .66 .66]);
linestyle = pb_keyval('linestyle',varargin,'none');
pb_selectfig(fig);
pb_selectaxis(ax);
hold on;
len = length(D);
rd = gobjects(len); rl = gobjects(len); h = gobjects(len);
%% Rawdata
for i = 1:len
iRT = 1/D(i).rt;
x = -1./sort(D(i).rt);
n = numel(iRT);
y = probitscale((1:n)./n);
rd(i) = plot(x,y,'Marker','o','Color',[.66 .66 .66],'MarkerFaceColor',[.66 .66 .66]);
end
%set(rd,'Tag','rawdata');
iRT = 1/D;
x = -1./sort(D);
n = numel(iRT);
y = probitscale((1:n)./n);
h(1) = plot(x,y,'Marker','o','Color',gcol,'MarkerFaceColor',gcol,'Linestyle','None');
set(h(1),'Tag','rawdata');
%% Quantiles & regression
p = [1,2,5,10,25,50,75,90 95 98 99]/100;
xtick = sort(-1./(150+[0 pb_oct2bw(50,-1:5)]));
p = [1,5,10,25,50,75,90, 95, 99]/100;
xtick = sort(-1./(150+[0 pb_oct2bw(50,-1:5)]));
for j = 1:len
prob = probit(p);
q = -1./quantile(D(j).rt,p);
b = regstats(prob,q);
prob = probitscale(p);
q = -1./quantile(D,p);
b = regstats(prob,q);
D(j).stats = b;
rl(j) = regline(b.beta,'k--');
h(j) = plot(q,prob,'o');
end
rl = regline(b.beta,'k--');
h(2) = plot(q,prob,'color',col,'Marker','o','MarkerFaceColor',col,'LineStyle',linestyle);
set(h,'Tag','probit model');
set(rl,'Tag','graphical aid: regline');
......@@ -67,7 +61,11 @@ function [h,D] = pb_probit(D, varargin)
axis square;
box off
pb_hline();
f = pb_fobj(gca,'Tag','horline');
if isempty(f)
f = pb_hline(0,'visibility','on');
set(f,'Tag','horline');
end
if ~ho; hold off; end
end
......
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