How to plot a line graph (x,y) with a color bar representing z-axis...

78 ビュー (過去 30 日間)
aa
aa 2020 年 9 月 18 日
編集済み: Rik 2020 年 9 月 21 日
I have data in multiple y and z axis...
x-axis is fixed while y-axis is varying with eah value of x and z is fixed for each (x,y) pair .... as shown in below figure ...
for example red colour show the fixed value of z-axis (color bar) ... and y is vary w.r.t x.. same is the case for other ..
Both data nd required plot is shown here ...

採用された回答

Rik
Rik 2020 年 9 月 18 日
編集済み: Rik 2020 年 9 月 21 日
You can use plot, colorbar, colormap, and caxis. You can adjust the line color by setting the Color property of the line object returned by plot.
If you have trouble implementing this, feel free to post a comment about which step exactly is causing you issues, and what you tried to solve it.
The code below was tested on R2011a as well, so it should work for R2013a. Next time, please mention all warnings or errors that you're getting, but most importantly: mention your release. It is 7.5 years old, which in software is very old.
data=xlsread('Pt_data.xlsx');
x=data(:,1);
y=data(:,2:2:end);
z=data(1,3:2:end);
%set z-axis
upper_z=1e-6;
lower_z=1e-9;
%create the colorbar, retrieve the colomap data, and let it match your example image
c=colorbar;
cmap=colormap('jet');
caxis([log10(lower_z) log10(upper_z)])
%set tick positions and create tick labels
Ticks=round(log10(lower_z)):round(log10(upper_z));
TickLabels=arrayfun(@(x) sprintf('10^{%d}',x),Ticks,'UniformOutput',false);
try
set(c,'Ticks',Ticks);
set(c,'TickLabels',TickLabels);
catch %HG1
TickLabels=strrep(strrep(TickLabels,'{',''),'}','');%remove TeX formatting
set(c,'YTick',Ticks);
set(c,'YTickLabel',TickLabels);
end
%normalize the z values to the color scale
z_scaled=(z-lower_z)./(upper_z-lower_z);
z_scaled(z_scaled<0)=0;z_scaled(z_scaled>1)=1;
z_scaled=round(1+z_scaled*(size(cmap,1)-1));%round to nearest index
%plot and select colors from colormap
hold on
for n=1:size(y,2)
C=cmap(z_scaled(n),:);
plot(x,y(:,n),'Color',C);
end
hold off
  12 件のコメント
aa
aa 2020 年 9 月 20 日
Sure ,,, whenever possible for you ... thank
Rik
Rik 2020 年 9 月 20 日
You can already edit your comment in the mean time.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by