How to set different part of a line with differnet color?
21 ビュー (過去 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!