Connecting points between two box plots
35 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I attached a picture of what I'm trying to plot to make it clear. I'm using the function notBoxPlot to create these "boxplots" and now I'd like to connect each point from the first boxplot to its counterpart in the second and third boxplot. I was told that I can use the command "line", however I could not figure it out despite reading the documentation and questions about connecting points (none of them seem to fit my problem).
I tried this for two boxplots but it does not yield any connecting lines at all. The vectors y1 and y2 are simply column vectors with 30 numbers each.
y1 = [CSPlus_shock]
y2 = [CSPlus_noshock]
notBoxPlot([y1,y2],[1:2])
hold on
line(y1,y2)
采纳的回答
the cyclist
2019-8-26
编辑:the cyclist
2019-8-26
I did not download notBoxPlot, but here is an example using a scatter plot instead.
% Some pretend data
N = 5;
x = [randn(N,1); 100+randn(N,1)]; % 5 points toward the left of the plot, and 5 toward the right
y = sort(randn(2*N,1));
% Scatter plot, and then connect each marker on the left
% to corresponding one on the right
figure
scatter(x,y)
line([x(1:N) x(N+1:end)]',[y(1:N) y(N+1:end)]')
I think the key to understanding how this works is to look at the array arguments to the line command.
There are 5 pairs of points in the plot. Each of the two argument to line is a 2x5 array:
line([2x5 array of x points],[2x5 array of y points])
Each column of that array has 2 values: (1) the x value of the left-hand point, and (2) the x value of the right-hand point. And similarly for the second argument of the line command, but using the y values.
If that's still a bit confusing, check out this syntax, which only draws one line between two points.
% Some pretend data
N = 5;
x = [randn(N,1); 100+randn(N,1)];
y = sort(randn(2*N,1));
% Scatter plot, and then connect *one* marker on the left
% to corresponding one on right
figure
scatter(x,y)
line([x(1) x(N+1)]',[y(1) y(N+1)]')
If you wanted to connect 5 sets of 3 data points, your line command would be
line([3x5 array of x points],[3x5 array of y points])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!