Fill plot with gradient colors
52 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sergio Yanez-Pagans
am 31 Okt. 2021
Verschoben: Adam Danz
am 20 Aug. 2023
I'm trying to plot a signal, for example cos(x), with a red gradient colormap for positive values and a blue one for negative values. Something similar to the solution previously discussed in:

I haven't been able to make this work for me, any suggestions?
2 Kommentare
Akzeptierte Antwort
Dave B
am 31 Okt. 2021
Bearbeitet: Dave B
am 31 Okt. 2021
x=linspace(0,4*pi,100);
y=cos(x);
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
figure
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
colormap jet
figure
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
colormap([cool;hot])
Or you could make your own colormap, just plug in red green and blue values that suit you (first column is red, second column is green, third column is blue):
figure
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
cmap = ones(256,3);
cmap(129:256,2)=linspace(0,1,128);
cmap(129:256,3)=linspace(0,1,128);
cmap(1:128,1)=linspace(1,0,128);
cmap(1:128,2)=linspace(1,0,128);
colormap(cmap);
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!