Fill plot with gradient colors

83 ビュー (過去 30 日間)
Sergio Yanez-Pagans
Sergio Yanez-Pagans 2021 年 10 月 31 日
移動済み: Adam Danz 2023 年 8 月 20 日
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 件のコメント
Star Strider
Star Strider 2021 年 11 月 1 日
I posted this Comment responding to a similar Comment in the referenced post.
Sergio Yanez-Pagans
Sergio Yanez-Pagans 2021 年 11 月 1 日
Thanks Strider!

サインインしてコメントする。

採用された回答

Dave B
Dave B 2021 年 10 月 31 日
編集済み: Dave B 2021 年 10 月 31 日
Here's one way to make the patch with the color gradient:
x=linspace(0,4*pi,100);
y=cos(x);
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
You could use jet or turbo to have blue on the bottom and red on the top:
figure
patch([x flip(x)],[y zeros(size(y))],[y zeros(size(y))])
colormap jet
Or you could mix hot and cool colormaps:
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 件のコメント
Sergio Yanez-Pagans
Sergio Yanez-Pagans 2021 年 11 月 1 日
移動済み: Adam Danz 2023 年 8 月 20 日
Thank you Dave, that was really useful!
Excellent answer =)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by