Plot connected vertical points with different marks
Mostrar comentarios más antiguos
I have a vector x=[ 1 2 3 4], and a matrix of size: 3x4.
I want to plot something like this:

Update: the number of vertical points can be different (in my example I used 3, but they can be from 2 to 5).
Update 2: "x" mark is not the center, it might happen than "x" mark is lower or higher than the other two points, for a particular x value.
Any ideas?
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 20 de Ag. de 2021
Try this:
markerSize = 14;
lineWidth = 2;
x = [1 2 3 4]
y = 0.1 + 0.4 * rand(3, 4)
[rows, columns] = size(y)
for col = 1 : columns
yTop = max(y(:, col));
yBottom = min(y(:, col));
yMid = setdiff(y(:, col), [yTop; yBottom]);
% Plot line
plot([x(col), x(col)], [yBottom, yTop], 'b-', 'LineWidth', 3);
hold on;
% Plot markers
plot(x(col), yTop, 'bd', 'LineWidth', lineWidth, 'MarkerSize', markerSize);
plot(x(col), yBottom, 'bo', 'LineWidth', lineWidth, 'MarkerSize', markerSize);
plot(x(col), yMid, 'bx', 'LineWidth', lineWidth, 'MarkerSize', markerSize);
end
grid on;

2 comentarios
Rub Ron
el 20 de Ag. de 2021
Image Analyst
el 20 de Ag. de 2021
Yeah, that was not specified. But it looks like you've accepted an answer so I guess you got it all figured out for the case of variable number of rows.
Categorías
Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


