display the data points to a boxplot
31 次查看(过去 30 天)
显示 更早的评论
I have the following data points:
x=[1,1,1,1,1,1,1,1,1,1,1,1,24,24,24,24,24,24,24,24,24,24,24,24,24,72,72,72,72,72,72,72,72,72,72,72,72,72,120,120,120,120,120,120,120,120,120,120,120,120,120,168,168,168,168,168,168,168,168,168,168,168,168,168,360,360,360,360,360,360];
y1=[3.4,3.6,10.4,8.6,15.2,20,4.6,8.8,8.4,1.6,0.6,3.6,1.07,0.28,0.75,3.48,0.43,3.17,3.58,0.77,0.59,2.19,0.17,0.25,0.56,2,0.18,0.56,3.93,2.28,2.23,2.39,2.51,0.31,1.04,0.08,0.2,0.56,1.6,0.28,0.39,3.34,1.86,2.22,2.72,2.21,0.25,0.63,0.48,0.14,0.53,1.45,0.22,0.53,2.54,1.45,1.8,2.29,2.2,0.18,0.49,0.48,0.17,0.42,1.04,0.13,0.63,2.06,0.25,0.33];
C=[14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29];
I would like to plot loglog plot of x and C. and boxplot of x and y1. I need both in the same figure. Also I want to display the data ponts o boxplot to be display on boxplot to understant the distribution. My code is:
x=[1,1,1,1,1,1,1,1,1,1,1,1,24,24,24,24,24,24,24,24,24,24,24,24,24,72,72,72,72,72,72,72,72,72,72,72,72,72,120,120,120,120,120,120,120,120,120,120,120,120,120,168,168,168,168,168,168,168,168,168,168,168,168,168,360,360,360,360,360,360];
y1=[3.4,3.6,10.4,8.6,15.2,20,4.6,8.8,8.4,1.6,0.6,3.6,1.07,0.28,0.75,3.48,0.43,3.17,3.58,0.77,0.59,2.19,0.17,0.25,0.56,2,0.18,0.56,3.93,2.28,2.23,2.39,2.51,0.31,1.04,0.08,0.2,0.56,1.6,0.28,0.39,3.34,1.86,2.22,2.72,2.21,0.25,0.63,0.48,0.14,0.53,1.45,0.22,0.53,2.54,1.45,1.8,2.29,2.2,0.18,0.49,0.48,0.17,0.42,1.04,0.13,0.63,2.06,0.25,0.33];
C=[14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2,2,2,2,2,2,2,2,2,2,2,2,2,1.49,1.49,1.49,1.49,1.49,1.49];
loglog(x,C,'LineWidth',3,'Color','c')
hold on
plot(x,y1,'o')
hold on
boxplot(y1, x)
hold on
I got the following output.
I dont know why only the first boxplot points are showing. I have made a rough sketch of what the required figure is as follows.
Can anybody help me? I am stuck with this for the last two days.
0 个评论
采纳的回答
jonas
2019-1-9
编辑:jonas
2019-1-9
The boxplot is not plotted against the correct x-values. The inserted x-array is treated as the grouping variable and the ticks are labelled accordingly, however the boxes are still plotted on x = [1 2 3 4...]. You can use the 'position' property to set the x-values.
figure;hold on
plot(x,y1,'o')
plot(x,C,'LineWidth',3,'Color','c')
boxplot(y1,x, 'positions',x)
set(gca,'xscale','log')
unfortunately the width of the boxes become inconsistent when setting the xscale to log.
6 个评论
jonas
2019-1-11
编辑:jonas
2019-1-11
Possible, yep. I'd probably do the following
box = findobj(gca,'tag','Box')
for i=1:numel(box)
prctls(i,1:2) = unique(box(i).YData)
end
prct25 = prctls(:,1);
prct75 = prctls(:,2);
Then you'd have all the ydata, and can plot the values using the text(x,y,'string') function.
text(flip(unique(log10(x))),prct25,flip(sprintfc('%.2g',prct25)))
You can then do the same for the median, just adapt the code ('tag' should be 'Median')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!