Dear All,
I am drawing several lines on one graph and I would like to make them thicker where they coincide. All advice gratefully accepted.
John Hey

4 件のコメント

Rik
Rik 2018 年 3 月 9 日
Could you give an example of realistic data? And what did you try so far?
John Hey
John Hey 2018 年 3 月 9 日
Dear Rik, Thanks for replying. Here is a graph I have produced. At the end all the lines coincide. I would like to make the thickness of the lines indicate how many lines coincide. Ant help would be greatly appreciated. John
Stephen23
Stephen23 2018 年 3 月 9 日
@John Hey: do all of the plotted lines use exactly the same X values?
John Hey
John Hey 2018 年 3 月 9 日
Stephen, Yes - they do. Does that help? John

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

 採用された回答

Stephen23
Stephen23 2018 年 3 月 10 日
編集済み: Stephen23 2018 年 3 月 10 日

0 投票

Here is one solution using NaN's to mask out parts of the lines, and plotting them for each thickness. For this to work it is also required to interpolate the data (try it without to see the difference). I don't claim that this is very efficient, but for a small number of lines and nodes it will work.
Xi = [1;2;3;4;5;6];
Yi = [1,2,2,2,1,1;2,2,2,2,3,4;3,3,3,3,3,4;4,3,3,3,4,5;5,5,2,2,4,4].';
plot(Xi,Yi,'LineWidth',3)
hold on
ylim([0,6])
N = numel(Xi);
Xo = interp1(1:N,Xi,1:0.5:N);
Yo = interp1(1:N,Yi,1:0.5:N);
D = bsxfun(@minus,Yo,permute(Yo,[1,3,2]))==0;
D = D(1:end-1,:,:) & D(2:end,:,:);
D = convn(D,[1;1])>0;
S = sum(D,3);
for k = 2:max(S(:))
Yo(S<k) = NaN;
plot(Xo,Yo,'k','LineWidth',k*3)
end
Giving:
You can adjust the colors and line thickness as you see fit. With some effort you could simplify and make it more efficient (e.g. remove columns with all NaN, or use indexing to extract only the non-NaN portions of M and plot only them).

その他の回答 (1 件)

elham kreem
elham kreem 2018 年 3 月 9 日

0 投票

let
y = 1:2:40
x1=4:2:43
x2 = 8:3:66
x3 = 1:4:80
figure ;
plot( x1 , y , ' r ' , x2 , y , ' b--o' , x3,y , 'g-*')

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2018 年 3 月 9 日

編集済み:

2018 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by