I would like to plot a graph and highlight edges with multiple colors, sometimes the same edge. If I use the highlight(h, G, ...) command it seems to overwrite the previous highlight command, even if I use hold on. Below is an illustrative example, the grah is a triangle on 1, 2, 3 and I wish to highlight edge 12 and 23 with 10 different colors in the hue scale, each with decreasing width. I added a pause command so the steps are visible and bunch of hold on's to see if any of them gives the desired result. But unfortunately the new highligh always overwrites the previous. I've tried additionally to create multiple edges but the highlight command colors all of them.
G = graph([1, 2, 1], [2, 3, 3]);
H = graph([1, 2],[2, 3]);
h = plot(G);
hold on
for I=1:10
hold on
highlight(h, H, 'EdgeColor', hsv2rgb([I/10, 1, 1]), 'LineWidth', 11-I);
hold on
pause(0.5);
end
hold off

 Akzeptierte Antwort

lewww
lewww am 27 Mär. 2021

0 Stimmen

I've solved it by plotting the same graph multiple times on the same plot and highlighting on each new plot the edges. Here's the solution for the example. It is kind of annoying to plot the same graph multiple times. It would be great to have the highlight function to work without overriding. Or an alternative solution would be that highlight returns the plot and further modifications can be called on the new plot.
G = graph([1, 2, 1], [2, 3, 3]);
H = graph([1, 2],[2, 3]);
for I=1:10
h = plot(G);
highlight(h, H, 'EdgeColor', hsv2rgb([I/10, 1, 1]), 'LineWidth', 11-I);
hold on
end
hold off

2 Kommentare

Walter Roberson
Walter Roberson am 27 Mär. 2021
The example https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.graphplot.highlight.html#buzh548 implies redrawing is not necessary; it makes two highlight() calls that do not appear to clash.
lewww
lewww am 27 Mär. 2021
Bearbeitet: lewww am 27 Mär. 2021
But in that example the second highlight only applies to nodes. The difference between node and edge highlighting seems to be the requirement that edge highlight requires the node set to be the same, meanwhile the node highlighting can work independently.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021a

Gefragt:

am 27 Mär. 2021

Bearbeitet:

am 27 Mär. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by