Creating a figure with multiple raincloud plots with the same y-axis

Hello,
I have made 4 raincloud plots which are subplotted as one image (attached image). However, I would like to have one x-y graph, with the 4 raincloud plots adjusted as one on top of the other, whereby the y-axis will not have the y values but they will identified the 4 groups.
Any help?
Thanks

Answers (1)

It would help if you woudl provide a drawing or other image of what you want.
It would also help if you attach the code you use to make the raincloud plot.
mu=[5 5.5 6]'; sigma=[.5 .45 .55]';
x=3.5:.01:7;
y=normpdf(x,mu,sigma);
offset=1;
colorspec=['r','g','b'];
for i=1:3
yoff=y(i,:)+(i-1)*offset;
base=zeros(1,length(x))+(i-1)*offset;
plot(x,yoff,'k');
hold on;
plot(x,base,'k');
x2 = [x, fliplr(x)];
inBetween = [base, fliplr(yoff)];
fill(x2,inBetween,colorspec(i));
end
set(gca,'YTickLabel',[]); %erase the numbers on y axis
Thank you to @Image Analyst for the code to shade between two plots.
Try it. Good luck.

6 Comments

Hi William,
Thanks for your reply. At the moment, I am using this code, where the raincloud_plot is a function provided:
f3 = figure('Position', fig_position);
subplot(2, 2, 1)
h1 = raincloud_plot(d{1}, 'box_on', 1, 'color',[0.2 0.67 0], 'MarkerFaceColor', [0.2 0.67 0]);
title('Visit 1');
set(gca, 'XLim', [300 1400]);
box off
subplot(2, 2, 2)
h2 = raincloud_plot(d{2}, 'box_on', 1,'color',[1 0.26 0], 'MarkerFaceColor', [1 0.26 0]);
title('Visit 2');
set(gca, 'XLim', [300 1400]);
box off
subplot(2, 2, 3)
h3 = raincloud_plot(d{3}, 'box_on', 1,'color', [0.63 0 1], 'MarkerFaceColor', [0.63 0 1]);
title('Visit 3'); %
set(gca, 'XLim', [300 1400]);
box off
subplot(2, 2, 4)
h4 = raincloud_plot(d{4}, 'box_on', 1,'color', [0.01 0.42 1], 'MarkerFaceColor', [0.01 0.42 1]);
title('Visit 4');
set(gca, 'XLim',[300 1400]);
box off
What if I deal with the h1 h2 h3 and h4 by trying to plot them together using a loop?
Thanks,
Eleonora
raincloud_plot() is not a built-in Matlab function, and I do not have it, so I cannot duplicate your results.
You can use a for loop to create an array of handles to the "raincloud_plot" objects.
mu=[5 5.3 5.7 6]; sigma=[.5 .45 .55 .4];
% Create 100x4 array of numbers
y=repmat(mu,100,1)+randn(100,4).*repmat(sigma,100,1);
% Generate raincloud plot for each column of the array
for i=1:4
h(i)=raincloud_plot(y(:,i))
end
Good luck.
Since I do not have the function raincloud_plot(), I cannot expriment with it, to learn how it behaves, or what options and properties it has.
The code you suggested above could be made into a loop as follows:
f3 = figure('Position', fig_position);
colorspec=[0.2 0.67 0; 1 0.26 0; 0.63 0 1; 0.01 0.42 1]
for i=1:4
subplot(2, 2, i)
h(i) = raincloud_plot(d{i}, 'box_on', 1, 'color',colorspec(i,:), 'MarkerFaceColor',colorspec(i,:));
titlestr=sprintf('Visit %d',i); title(titlestr);
set(gca, 'XLim', [300 1400]);
box off
end
If you do not plan to access the properties of each raincloud plot, then you do not need the handles h(i). In that case, you could replace the line h(i)=raincloud_plot(...); with raincloud_plot(...); .
mu=[5 5.5 6]'; sigma=[.5 .45 .55]';
x=3.5:.01:7;
y=normcdf(x,mu,sigma);
offset=1;
colorspec=['r','g','b'];
for i=1:3
yoff=y(i,:)+(i-1)*offset;
base=zeros(1,length(x))+(i-1)*offset;
plot(x,yoff,'k');
hold on;
plot(x,base,'k');
x2 = [x, fliplr(x)];
inBetween = [base, fliplr(yoff)];
fill(x2,inBetween,colorspec(i));
end
set(gca,'YTickLabel',[]); %erase the numbers on y axis
not working can you provide code for cdf plotting
Try cdfplot(). If that does not work for you, then post a new question on Matlab Answers. Good luck.
i try for cdfplot() but it is not working

Sign in to comment.

Asked:

on 28 Nov 2022

Commented:

on 11 Mar 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!