color-coding a 2D plot

26 ビュー (過去 30 日間)
Vahid
Vahid 2012 年 3 月 27 日
Hello everybody,
I am wondering how we can plot a 2D figure,x vs. y, which the amplitude of a given mathematical function, let say f(x,y) where e.g. f=sqrt(x.^2+y.^2), is encoded with colors in 2D plot as if max(f) is shown with e.g. blue color and min(f) with red color.
thank you so much, --V

採用された回答

Kevin Holst
Kevin Holst 2012 年 3 月 27 日
unfortunately shading interp doesn't seem to work on contourf so here's an inelegant solution to your problem.
[x,y] = meshgrid(-10:0.1:10,-10:0.1:10); % just to get some x and y values
z = sqrt(x.^2 + y.^2);
surf(x,y,z)
shading interp
set(gca,'cameraposition',[0 0 180]) % this essentially turns a 3d surface plot into a 2d plot
colormap(flipud(jet))
  1 件のコメント
Vahid
Vahid 2012 年 3 月 27 日
nice solution! thanks again :-D

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

その他の回答 (2 件)

Kevin Holst
Kevin Holst 2012 年 3 月 27 日
how about:
[x,y] = meshgrid(-10:0.1:10,-10:0.1:10); % just to get some x and y values
z = sqrt(x.^2 + y.^2);
contourf(x,y,z)
colormap(flipud(jet))
Is that what you're envisioning?

Vahid
Vahid 2012 年 3 月 27 日
Thanks Kevin! What I am looking for is very close to what your commands plot. I'd like to have a continuous color changing rather than using different colors, I mean contentiously changing from [0 0 1] to [1 0 0] which each three-element row vector is the RGB triple.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by