Specify Square Marker in a Plot
450 次查看(过去 30 天)
显示 更早的评论
For a plot like below:
X = (1:25);
Y = [2 1 2 2 2 3 1 4 3 2 1 2 3 7 11 8 5 2 3 4 5 8 5 5 7];
fig1 = figure();
set(fig1,'color','white')
plot(X,Y,'-s',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','r',...
'MarkerFaceColor',[0.3,0.3,0.3])
How can I specify a red square marker only for the points with Y value equal or bigger than 8, and for the rest a blue square? So for the figure above, I want the square markers at points with X value of 15, 16 and 22 to be red and the rest to be blue. Thank you!
1 个评论
Jeffrey Clark
2022-6-19
@MarshallSc, plot the line ('-') separate from the points, then with hold on do two plots of only the marker ('s'). one where X(Y>8) and Y(Y>8) and the other X(Y<=8) and Y(Y<=8). Using something like selected = Y>8 you can then use selected and ~selected in the X and Y plot selections.
采纳的回答
Voss
2022-6-19
You can break it up into multiple lines:
X = (1:25);
Y = [2 1 2 2 2 3 1 4 3 2 1 2 3 7 11 8 5 2 3 4 5 8 5 5 7];
fig1 = figure();
set(fig1,'color','white')
plot(X,Y,'-',...
'LineWidth',2);
hold on
idx = Y >= 8;
plot(X(idx),Y(idx), ...
'Marker','s', ...
'LineStyle','none', ...
'MarkerSize',10,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r');%[0.3,0.3,0.3])
plot(X(~idx),Y(~idx), ...
'Marker','s', ...
'LineStyle','none', ...
'MarkerSize',10,...
'MarkerEdgeColor','b',...
'MarkerFaceColor','b');%[0.3,0.3,0.3])
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!