How do I construct a line plot with markers having different colors?
조회 수: 3 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2018년 4월 20일
답변: MathWorks Support Team
2018년 4월 23일
I have two 5 x 1 vectors 'x' and 'y' containing the x and y locations of my points. I have a matrix 'col' which is 3 x 5 and contains the colors I want for the markers:
[0 0 1
0 1 0
1 0 0
1 0 1
0 1 1]
I am plotting the line using this command :
x = [1 2 3 4 5]; y = [2 4 3 2 6];
plot(x, y, '-ko', 'MarkerFaceColor', 'red')
How can I control the color of individual markers ?
채택된 답변
MathWorks Support Team
2018년 4월 20일
You cannot achieve this with the 'plot' command as it does not offer the functionality to control styles for individual markers on a line plot.
However, you can use the 'scatter' function to control the color for individual markers and use the 'plot' command to overlay it with your line plot.
For example :
x = [1 2 3 4 5];
y = [2 4 3 2 6];
c = [ 0 0 1; 0 1 0; 1 0 0; 1 0 1; 0 1 1];
f = plot(x, y, '-')
hold on
scatter(x,y, [], c, 'filled')
hold off
댓글 수: 0
추가 답변 (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!