1D Plot with custom colours
显示 更早的评论
Say I need to plot two vectors x and y using a standard line plot. What is the fastest way to color each point of the graph depending on the quadrant it's in (so that for example the portion of the graph inside the first quadrant is blue, the one in the second quadrant is red etc.)?
回答(1 个)
Walter Roberson
2020-9-9
编辑:Walter Roberson
2020-9-9
0 个投票
plot() as usual to get the vectors. Then scatter() markers on top of that, passing in the color information as the fourth parameter, scatter(x, y, size, color)
You cannot solve this with a single plot() call or a single scatter() call by themselves. plot() does not permit different colors for the same line, and scatter() cannot join points.
There is also a possibility using patch(). There is a File Exchange contribution for colored lines that is based upon patch()
类别
在 帮助中心 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!