2D Colored Plot

2 vues (au cours des 30 derniers jours)
Noah Reilly
Noah Reilly le 24 Juil 2021
Réponse apportée : KSSV le 24 Juil 2021
Hello, I've created a script which runs for 100 different values of x and produces 3 different values of Y for each X.
Currently I have these lineplotted, but I think that's kinda boring and I would like to present the data differently.
Below is the current plot
I'd like it so that for every X value where one of the lines has a greater value than the other 2 it is colored in a certain color. Kinda like a contour or surface plot, but without a value for Z. I was thinking some sort of contour or heat map, but neither of those sound like they fit what I need. What plot would you suggest, if any, to do this.
For example. Between X values 1 to 14, the entire plot would be red, between 14 and 29 it'd be blue, and past 29 it'd be yellow.
I'd prefer if you pointed me in the right direction instead of just giving me code for this question, I really wanna learn how to do this because it's not something they taught in my coding course.

Réponses (1)

KSSV
KSSV le 24 Juil 2021
You can get the indices of the required values and plot them with different colors.
x = 0:.05:2*pi;
y = sin(x);
figure
hold on
plot(x(y>=0),y(y>=0),'r')
plot(x(y<0),y(y<0),'b')

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by