Borrar filtros
Borrar filtros

Connecting points between two box plots

31 visualizaciones (últimos 30 días)
RP
RP el 26 de Ag. de 2019
Comentada: darova el 26 de Ag. de 2019
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)

Respuesta aceptada

the cyclist
the cyclist el 26 de Ag. de 2019
Editada: the cyclist el 26 de Ag. de 2019
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])
  1 comentario
RP
RP el 26 de Ag. de 2019
Ahhh this works! Thank you so much! And such a great detailed explanation, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by