### maybe a better way to create rm rainclouds

parent 757c1f2d
 %% WORK IN PROGRESS % it might be that 'patch' is a much better plotting function to plot the % densities than 'area'; it seems to handle over-plotting of different % areas with different zero lines very well. This would avoid the horrible % gymnastics that the repeated measures lineplot currently has to deal % with. % This is a work-in-progress example inspired by this post on Matlab % answers https://uk.mathworks.com/matlabcentral/answers/1387-area-plot-with-gradient % For that reason the density plots also now have colour gradients which I % think look rather nice... zero_line_for_second_plot = 1.1; nbins = 200; ndatapoints = 80; d = abs(randn(1,ndatapoints).^1.2); [ks,x] = ksdensity(d,'NumPoints',nbins); d2 = abs(randn(1,ndatapoints).^0.7); [ks2,x2] = ksdensity(d2,'NumPoints',nbins); cl = flipud(cbrewer('seq','Purples',nbins)); cl2 = flipud(cbrewer('seq','Greens',nbins)); f = ks; f2 = ks2 + zero_line_for_second_plot; % Define the vertices: the points at (x, f(x)) and (x, 0) N = length(x); verts = [x(:), f(:); x(:) zeros(nbins,1)]; verts2 = [x2(:), f2(:); x2(:) ones(nbins,1)*zero_line_for_second_plot]; % give it a different zero % Define the faces to connect each adjacent f(x) and the corresponding points at y = 0. q = (1:N-1)'; faces = [q, q+1, q+N+1, q+N]; figure; hold on p = patch('Faces', faces, 'Vertices', verts, 'FaceVertexCData', [cl;cl], 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceAlpha',0.5); p2 = patch('Faces', faces, 'Vertices', verts2, 'FaceVertexCData', [cl2;cl2], 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceAlpha',0.5); jitwidth = 0.15; jit = jitwidth + rand(1,ndatapoints) * jitwidth; jit2 = jitwidth + rand(1,ndatapoints) * jitwidth; sz = 100; s = scatter(d,-jit,'MarkerFaceColor',cl(15,:),'MarkerEdgeColor','none', 'MarkerFaceAlpha', 0.5, 'SizeData', sz); s2 = scatter(d2,-jit2+zero_line_for_second_plot,'MarkerFaceColor',cl2(15,:),'MarkerEdgeColor','none', 'MarkerFaceAlpha', 0.5, 'SizeData', sz);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!