Plot graph with different markers

139 Ansichten (letzte 30 Tage)
Rub Ron
Rub Ron am 9 Feb. 2020
Bearbeitet: dpb am 14 Jul. 2023
Hello, I have a graph G lets say with 100 egdes and 40 nodes. The G.nodes are of 3 types stored in a vector type (40x1). How can I plot the graph so that each node adopt the mark corresponding to its type?
h = plot(G,'NodeLabel',mylabel);
mylabel is a 0x1 vector with the labelling of the nodes.
Any references would be really appreciatted.

Akzeptierte Antwort

dpb
dpb am 9 Feb. 2020
See <Marker in Graphplot properties>. Pass an index array to the position of the desired marker type as the 'Marker' property.
mkrs=['o';'x','+']; % the desired markers lookup table
Gtype=[....]; % vector of 1,2,3 defining which marker for each element of G
hG=plot(G,'Marker',mkrs(Gtype));
Property 'NodeLabel' could be used to write some label instead of using the plot marker by the same lookup logic if your desired labels are something different than available plot markers.
  3 Kommentare
KHAN MUBASHER AHMED
KHAN MUBASHER AHMED am 14 Jul. 2023
I have tried running the code given above but I cannot seem to get it to run.
I get an errir of invalid enum value. Can someone please help?
mkrs = {'o','x','+'};
Gtype=[1 2 3];
G = [2,4,6]
G = 1×3
2 4 6
hG=plot(G,'Marker',mkrs(Gtype));
Error using plot
Invalid enum value. Use one of these values: '+' | 'o' | '*' | '.' | 'x' | 'square' | 'diamond' | 'v' | '^' | '>' | '<' | 'pentagram' | 'hexagram' | '|' | '_' | 'none'.
dpb
dpb am 14 Jul. 2023
Bearbeitet: dpb am 14 Jul. 2023
plot is a single line object for each vector; hence you can't put more than one marker on a given line; the syntax above lets you select which one of the array markers to use on a given line/call, Gtype is a specific index into the array, not a vector. And, btw, the char() array shown will also work since each element is a single character, it doesn't require any fixup--although a cellstr may be preferable in many uses, it isn't necessary here, although it (or the newer yet string array) can be used here.
To put multiple markers on a given line, draw the line first, then use scatter for the markers; there's no combination of one line with multiple markers as a single object available. Of course, this sequence requires hold on to put the second graphics object on the same axes.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by