Hi!
I want to plot a vector where certain elements are somehow "better" and should be plotted as thicker lines. Still they should be the same line, only that it is thicker during some parts.

 採用された回答

Rik
Rik 2018 年 2 月 21 日

0 投票

I doubt this is possible with a single line object, but you can still do this. You can use the fact that plot will stop plotting at a NaN-value and resume when normal values occur again. So you can use your definition of better to replace the values that are worse with NaN. Then you just need to use hold(gca,'on') and plot again, with LineWidth set to a larger value.

7 件のコメント

Hampus Alfredsson
Hampus Alfredsson 2018 年 2 月 21 日
Ok, like I suspected...but your solution could do the job! The only problem is that I will do approximately 10 line plots and probably want to make 5-10 intervals thicker in each of them. It will become a large plot.
Rik
Rik 2018 年 2 月 21 日
I don't fully understand your problem. Could you give an example? The number of intervals doesn't really matter, as plot will just resume the plotting for valid intervals.
Hampus Alfredsson
Hampus Alfredsson 2018 年 2 月 21 日
I have a long matrix of coordinates representing the geographic movements of several bus lines. Whenever two or more bus lines use the same road(set of coordinates) this should be noted somehow. The more bus lines using the same coordinated should increase the thickness of these coordinates later in my plot. Don't know how to give a better explanation than this.
Rik
Rik 2018 年 2 月 21 日
As long as you insert NaN-values when you overlay the thicker lined plot, there shouldn't be a difference. You can even use a loop to go over all pair widths.
Hampus Alfredsson
Hampus Alfredsson 2018 年 2 月 21 日
Ok, so if I use this example with some vectors:
A = [1 2 3 4];
B = [3 5 6 2];
C = [7 8 9 3];
All numbers that are repeated should be plotted as thicker. So number 2 should be a bit thicker and number 3 should be the most. How would you do?
Rik
Rik 2018 年 2 月 22 日
So you are actually plotting a graph. There is a built-in that does that (since R2015b). You can even supply the weights for each edge. The example code below is from the graph.plot doc. The doc for the graph function itself can be found here.
s = [1 1 1 1 2 2 3 4 4 5 6];
t = [2 3 4 5 3 6 6 5 7 7 7];
weights = [50 10 20 80 90 90 30 20 100 40 60];
G = graph(s,t,weights)
LWidths = 5*G.Edges.Weight/max(G.Edges.Weight);
plot(G,'EdgeLabel',G.Edges.Weight,'LineWidth',LWidths)
The s and t vectors contain the starting node index and terminal node index for each edge (=line in your plot). The weight determines the thickness of each line.
Hope this helps. I don't think you have supplied enough information for me to provide an example with your data.
Hampus Alfredsson
Hampus Alfredsson 2018 年 2 月 22 日
Thank you very much @Rik Wisselink

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by