1D Plot with custom colours

3 visualizzazioni (ultimi 30 giorni)
Marco Vona
Marco Vona il 8 Set 2020
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.)?

Risposte (1)

Walter Roberson
Walter Roberson il 9 Set 2020
Modificato: Walter Roberson il 9 Set 2020
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()

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by