How to set different part of a line with differnet color?
조회 수: 26 (최근 30일)
이전 댓글 표시
Hi all,
Suppose I want to draw a plot with command: plot(1:220, data, '.-'); The output line has a uniform color throughout the range. Now I hope to set the line color to blue for points have x-coordinate [1, 100], to red for points on [101, 150] and black on [151, 220]. How can I make it? Thanks a lot for your answer.
댓글 수: 0
답변 (2개)
dpb
2016년 9월 17일
Have to draw three lines; the color property is a single value for each line object. Also then note that to have continuous lines you'll have to include the bounding endpoints for each set of lines to include the last of the other group and that the line will switch color at the breakpoint. One way to do this would be to duplicate the data into three columns with NaN for the unwanted points in each column; then a single plot call will draw the three lines.
댓글 수: 0
David Goodmanson
2016년 9월 17일
After you divide your data into three separate sets, use 'help plot' (fifth paragraph) to see how to put them on the same plot, and also how to select a separate line color for each part.
For multi-line plots, Matlab's automatic colors are much more attractive than they used to be. Unfortunately, the manual color options in the plot command still give you old-fashioned fully saturated colors, including a yellow that's hard to see, and a hideous bright green. This has been going on forever and should have been changed years ago. (Mathworks, are you listening?)
댓글 수: 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!