Commit 22afdba3 authored by Tom's avatar Tom

fixed y-axis label and autosizing density plots

parent 949fe68c
......@@ -27,11 +27,7 @@ function h = toy_example_with_patch(d,cl)
assert(all(size(cl) == [nseries 3]), 'number of colors does not match number of plot series');
%%
% TO-DO: These shouldn't be hard-coded, but calculated somehow. How?
% (spacings between rainclouds)
% ALSO NOTE: This way plots the first data in the series on the top
ks_offsets = [2 1 0];
% NOTE: This way plots the first data in the series on the *bottom*
% Probably okay to hard-code this as it just determines the granularity of
% the density estimate
......@@ -43,9 +39,17 @@ for i = 1:nper
% calculate kernel densities
[ks{i,j},x{i,j}] = ksdensity(d{i,j},'NumPoints',nbins);
% TO-DO: Switch here to use alternative methods to estimate density (e.g. RASH)
end
end
spacing = 2 * mean(mean(cellfun(@max,ks)));
ks_offsets = [0:nper-1] .* spacing;
for i = 1:nper
for j = 1:nseries
% calculate patch vertices from kernel density
verts{i,j} = [x{i,j}', ks{i,j}'+ ks_offsets(i); x{i,j}', ones(nbins,1)*ks_offsets(i)];
verts{i,j} = [x{i,j}', ks{i,j}'+ ks_offsets(i); x{i,j}', ones(nbins,1)*ks_offsets(i)];
end
end
......@@ -58,7 +62,7 @@ faces = [q, q+1, q+nbins+1, q+nbins];
%% jitter for the raindrops
% TO-DO: These should probably not be hardcoded either...
jitwidth = 0.15;
jitwidth = spacing / 8;
sz = 100;
for i = 1:nper
......@@ -88,18 +92,24 @@ for i = 1:nper
end
end
% mean lines
% plot mean lines
for i = 2:nper % note 2, not 1. We have nper-1 lines because lines connect pairs of points
for j = 1:nseries
line(mnz([i-1 i],j),ks_offsets([i-1 i]),'LineWidth', 4,'Color',cl(j,:));
end
end
% mean dots
% plot mean dots
for i = 1:nper
for j = 1:nseries
h.m(i,j) = scatter(mnz(i,j),ks_offsets(i),'MarkerFaceColor',cl(j,:),'MarkerEdgeColor',[0 0 0], 'MarkerFaceAlpha', 1, 'SizeData', sz*2, 'LineWidth', 2);
end
end
% keyboard
%% clear up axis labels
set(gca,'YTick',ks_offsets);
set(gca,'YTickLabel',1:nper);
%%
keyboard
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