フィルターのクリア

Several line plot (2D) with colormap (including labelling)

3 ビュー (過去 30 日間)
Askeladden2
Askeladden2 2023 年 1 月 4 日
コメント済み: Dyuman Joshi 2023 年 1 月 5 日
Dear All Community Members,
I have about 300 lines that I want to be colored depending on a third value in one plot.
I have created a simplified example below to illustrate my problem:
I have 6 lines. The coordinates of the lines are given in the matrices 'x' and 'y' below:
x=[1,3,5,1,3,5;2,4,6,2,4,6]
y=[1,1,1,-1,-1,-1;1,1,1,-1,-1,-1]
The coloring of the lines depends on the values given in vector 'z' below:
z=[3.1,2.2,4.8,1.6,2.9,3.7]
I would also like to add a color label to the plot.
The output plot shall be as below:
N.B. I dont need the text above the lines.
Can anyone assist me?
I appreciate any help you can provide.
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 4 日
How do the z values co-relate to the color values?
What are the boundaries of colors as set in the colorbar in the image you attached?
The rest has been done -
x=[1,3,5,1,3,5;2,4,6,2,4,6];
y=[1,1,1,-1,-1,-1;1,1,1,-1,-1,-1];
z=[3.1,2.2,4.8,1.6,2.9,3.7];
plot(x, y, 'LineWidth', 2)
axis([0 8 -2 2])
colorbar('east')
Askeladden2
Askeladden2 2023 年 1 月 4 日
Thank you for your swift reply.
I want the lines and colorbar to be adjusted automatically to the values in the z vector, if that is possible.
The color boundaries given the example is as follows:
Lines with z-values between 1-1.75 shall be colored red
Lines with z-values between 1.75-2.6 shall be colored orange
Lines with z-values between 2.6-3.4 shall be colored yellow
Lines with z-values between 3.4-4.2 shall be colored green.
Lines with z-values above 4.2 shall be colored blue.

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 1 月 4 日
x=[1,3,5,1,3,5;2,4,6,2,4,6];
y=[1,1,1,-1,-1,-1;1,1,1,-1,-1,-1];
z=[3.1,2.2,4.8,1.6,2.9,3.7];
%defining colormap
map=[255 0 0;255 165 0;255 255 0;0 255 0;0 0 255]/255;
%interpolating values according to z
yo=interp1(1:5,map,z);
%plotting
for i=1:size(x,2)
plot(x(:,i), y(:,i), 'LineWidth', 2.5, 'Color', yo(i,:))
hold on
end
hold off
%adjusting other properties
axis([0 8 -2 2])
colormap(map)
caxis([1 5])
colorbar('Position', [0.8 0.25 0.04 0.6])
  2 件のコメント
Askeladden2
Askeladden2 2023 年 1 月 5 日
Works perfect.
Thank you very much!
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 5 日
You are welcome!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by