How to display dark edges over lighter ones in Matlab plots?2019 Community Moderator ElectionHow to draw a surface plot without black edges in MATLAB?Changing Fonts Size in Matlab PlotsSave plot to image file instead of displaying it using MatplotlibHow should I update the data of a plot in Matlab?vetical line in matlab semilogy plotMatlab bar3 plotMatlab scatter markers bleed over edge of plotMultiple plots in a single graph using Gramm in MatlabHow to plot all nodes in a graph using MATLABUpdate Plot in Matlab
IBM PAT Number Sequence
If I receive a SOS signal, what is the proper response?
How do I express some one as a black person?
cat shows nothing
Can I pump my MTB tire to max (55 psi / 380 kPa) without the tube inside bursting?
What problems would a superhuman have whose skin is constantly hot?
How to draw cubes in a 3 dimensional plane
Plausibility of Mushroom Buildings
'The literal of type int is out of range' con número enteros pequeños (2 dígitos)
How is the wildcard * interpreted as a command?
Counting all the hearts
Death from old age has stopped, but fertility window is the same. What is the new population equlibrium?
When stopping and starting a tile job, what to do with the extra thinset from previous row's cleanup?
Do items de-spawn in Diablo?
Why the color red for the Republican Party
Do I really need to have a scientific explanation for my premise?
Could you please stop shuffling the deck and play already?
Do f-stop and exposure time perfectly cancel?
When traveling to Europe from North America, do I need to purchase a different power strip?
Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?
Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?
Why is computing ridge regression with a Cholesky decomposition much quicker than using SVD?
How strictly should I take "Candidates must be local"?
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
How to display dark edges over lighter ones in Matlab plots?
2019 Community Moderator ElectionHow to draw a surface plot without black edges in MATLAB?Changing Fonts Size in Matlab PlotsSave plot to image file instead of displaying it using MatplotlibHow should I update the data of a plot in Matlab?vetical line in matlab semilogy plotMatlab bar3 plotMatlab scatter markers bleed over edge of plotMultiple plots in a single graph using Gramm in MatlabHow to plot all nodes in a graph using MATLABUpdate Plot in Matlab
I have the following Matlab plot representing a graph. I would like to display the darker on top of the lighter ones in such a way the lighter edges don't modify the darker when crossing them. How could I do?
Edit: the Matlab code for reproduce the example is the following
plot(G, 'XData', Xcoords, 'YData', Ycoords,'NodeLabel',, 'MarkerSize', 7,...
'Linewidth',1.6, 'EdgeCData', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside');
caxis([min(G.Edges.Weight) max(G.Edges.Weight)])
axis off
where the weights of the edges are encoded in G.Edges.Weight
To reproduce the effect (with a smaller graph), you can try with the following code:
A= zeros(4,4);
A(1,[2 3 4])=1;
A(2,4)=0.04;
A(2,[1 3])=1;
A(3,[2 1 4])=1;
A(4,2)=0.04;
A(4,[3 1])=1;
Xcoords=[1 2 2 1]';
Ycoords= [1 1 2 2 ]';
G= graph(A);% base toolbox
figure()
plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
It seems that is the ordering of the edges that decide who is on top. For instance, if the weight 0.04 is assigned to the other crossing edge (A(1,3)=A(3,1)) the effect is not visible since the edge A(2,4)=A(4,2) cames after.
matlab plot graph matlab-figure
|
show 2 more comments
I have the following Matlab plot representing a graph. I would like to display the darker on top of the lighter ones in such a way the lighter edges don't modify the darker when crossing them. How could I do?
Edit: the Matlab code for reproduce the example is the following
plot(G, 'XData', Xcoords, 'YData', Ycoords,'NodeLabel',, 'MarkerSize', 7,...
'Linewidth',1.6, 'EdgeCData', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside');
caxis([min(G.Edges.Weight) max(G.Edges.Weight)])
axis off
where the weights of the edges are encoded in G.Edges.Weight
To reproduce the effect (with a smaller graph), you can try with the following code:
A= zeros(4,4);
A(1,[2 3 4])=1;
A(2,4)=0.04;
A(2,[1 3])=1;
A(3,[2 1 4])=1;
A(4,2)=0.04;
A(4,[3 1])=1;
Xcoords=[1 2 2 1]';
Ycoords= [1 1 2 2 ]';
G= graph(A);% base toolbox
figure()
plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
It seems that is the ordering of the edges that decide who is on top. For instance, if the weight 0.04 is assigned to the other crossing edge (A(1,3)=A(3,1)) the effect is not visible since the edge A(2,4)=A(4,2) cames after.
matlab plot graph matlab-figure
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
Can you show some sample code to createG
?
– Mad Physicist
Mar 5 at 21:17
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25
|
show 2 more comments
I have the following Matlab plot representing a graph. I would like to display the darker on top of the lighter ones in such a way the lighter edges don't modify the darker when crossing them. How could I do?
Edit: the Matlab code for reproduce the example is the following
plot(G, 'XData', Xcoords, 'YData', Ycoords,'NodeLabel',, 'MarkerSize', 7,...
'Linewidth',1.6, 'EdgeCData', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside');
caxis([min(G.Edges.Weight) max(G.Edges.Weight)])
axis off
where the weights of the edges are encoded in G.Edges.Weight
To reproduce the effect (with a smaller graph), you can try with the following code:
A= zeros(4,4);
A(1,[2 3 4])=1;
A(2,4)=0.04;
A(2,[1 3])=1;
A(3,[2 1 4])=1;
A(4,2)=0.04;
A(4,[3 1])=1;
Xcoords=[1 2 2 1]';
Ycoords= [1 1 2 2 ]';
G= graph(A);% base toolbox
figure()
plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
It seems that is the ordering of the edges that decide who is on top. For instance, if the weight 0.04 is assigned to the other crossing edge (A(1,3)=A(3,1)) the effect is not visible since the edge A(2,4)=A(4,2) cames after.
matlab plot graph matlab-figure
I have the following Matlab plot representing a graph. I would like to display the darker on top of the lighter ones in such a way the lighter edges don't modify the darker when crossing them. How could I do?
Edit: the Matlab code for reproduce the example is the following
plot(G, 'XData', Xcoords, 'YData', Ycoords,'NodeLabel',, 'MarkerSize', 7,...
'Linewidth',1.6, 'EdgeCData', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside');
caxis([min(G.Edges.Weight) max(G.Edges.Weight)])
axis off
where the weights of the edges are encoded in G.Edges.Weight
To reproduce the effect (with a smaller graph), you can try with the following code:
A= zeros(4,4);
A(1,[2 3 4])=1;
A(2,4)=0.04;
A(2,[1 3])=1;
A(3,[2 1 4])=1;
A(4,2)=0.04;
A(4,[3 1])=1;
Xcoords=[1 2 2 1]';
Ycoords= [1 1 2 2 ]';
G= graph(A);% base toolbox
figure()
plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight)
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
It seems that is the ordering of the edges that decide who is on top. For instance, if the weight 0.04 is assigned to the other crossing edge (A(1,3)=A(3,1)) the effect is not visible since the edge A(2,4)=A(4,2) cames after.
matlab plot graph matlab-figure
matlab plot graph matlab-figure
edited Mar 7 at 11:27
Will
1,128617
1,128617
asked Mar 5 at 19:40
AlbertoAlberto
418
418
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
Can you show some sample code to createG
?
– Mad Physicist
Mar 5 at 21:17
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25
|
show 2 more comments
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
Can you show some sample code to createG
?
– Mad Physicist
Mar 5 at 21:17
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
Can you show some sample code to create
G
?– Mad Physicist
Mar 5 at 21:17
Can you show some sample code to create
G
?– Mad Physicist
Mar 5 at 21:17
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25
|
show 2 more comments
1 Answer
1
active
oldest
votes
The order of the edge table in MATLAB's graph
class seems pretty tightly dependent on position in the graph's adjacency matrix, which is inherently impossible to contrive in a way that guarantees some arbitrary edge order. So I think you only have two options:
- Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.
- Manipulate MATLAB's graph plotting output using the undocumented primitives it creates.
The second option is possible by noting that the plotted GraphPlot
object has a LineStrip
object in its NodeChildren
which is responsible for drawing all the relevant edges. Because you're using a grayscale color map, the RGB data in this object is all you need to figure out how its vertices need to be ordered to get the right plot order.
First, store the plotted result in P
and set EdgeAlpha
to 1
so the graph is plotted
in such a way the lighter edges don't modify the darker when crossing them
P = plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight, 'EdgeAlpha',1);
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
Then find the LineStrip
created in the drawing process:
drawnow
s = P.NodeChildren(arrayfun(@(o) isa(o,'matlab.graphics.primitive.world.LineStrip'), P.NodeChildren));
The new order of the vertices in s
can then be determined from its ColorData
, which must then be applied to both the ColorData
and VertexData
properties to reorder the edges without anything else changing:
[~,idx] = sortrows(s.ColorData','desc');
set(s, 'VertexData',s.VertexData(:,idx), 'ColorData',s.ColorData(:,idx));
This will be liable to be overridden by any further redrawing that takes place and being undocumented functionality comes with no guarantees as to how it will behave – but superficially it seems to do what you're looking for.
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digitingP.
the automatic compilation does not showNodeChildren
yetChilden
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?
– Alberto
Mar 7 at 9:06
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.NodeChildren
is a hidden property of graphics objects andLineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods likemetaclass
to discover them.
– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
@Alberto have you been running the code above all in one go? I've realised the objects in theNodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to calldrawnow
before accessing the primitives inNodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.
– Will
Mar 8 at 9:11
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. TheGraphPlot
object has a hidden eventMarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires usingaddlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try
– Will
Mar 8 at 16:28
|
show 6 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55010337%2fhow-to-display-dark-edges-over-lighter-ones-in-matlab-plots%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The order of the edge table in MATLAB's graph
class seems pretty tightly dependent on position in the graph's adjacency matrix, which is inherently impossible to contrive in a way that guarantees some arbitrary edge order. So I think you only have two options:
- Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.
- Manipulate MATLAB's graph plotting output using the undocumented primitives it creates.
The second option is possible by noting that the plotted GraphPlot
object has a LineStrip
object in its NodeChildren
which is responsible for drawing all the relevant edges. Because you're using a grayscale color map, the RGB data in this object is all you need to figure out how its vertices need to be ordered to get the right plot order.
First, store the plotted result in P
and set EdgeAlpha
to 1
so the graph is plotted
in such a way the lighter edges don't modify the darker when crossing them
P = plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight, 'EdgeAlpha',1);
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
Then find the LineStrip
created in the drawing process:
drawnow
s = P.NodeChildren(arrayfun(@(o) isa(o,'matlab.graphics.primitive.world.LineStrip'), P.NodeChildren));
The new order of the vertices in s
can then be determined from its ColorData
, which must then be applied to both the ColorData
and VertexData
properties to reorder the edges without anything else changing:
[~,idx] = sortrows(s.ColorData','desc');
set(s, 'VertexData',s.VertexData(:,idx), 'ColorData',s.ColorData(:,idx));
This will be liable to be overridden by any further redrawing that takes place and being undocumented functionality comes with no guarantees as to how it will behave – but superficially it seems to do what you're looking for.
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digitingP.
the automatic compilation does not showNodeChildren
yetChilden
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?
– Alberto
Mar 7 at 9:06
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.NodeChildren
is a hidden property of graphics objects andLineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods likemetaclass
to discover them.
– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
@Alberto have you been running the code above all in one go? I've realised the objects in theNodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to calldrawnow
before accessing the primitives inNodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.
– Will
Mar 8 at 9:11
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. TheGraphPlot
object has a hidden eventMarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires usingaddlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try
– Will
Mar 8 at 16:28
|
show 6 more comments
The order of the edge table in MATLAB's graph
class seems pretty tightly dependent on position in the graph's adjacency matrix, which is inherently impossible to contrive in a way that guarantees some arbitrary edge order. So I think you only have two options:
- Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.
- Manipulate MATLAB's graph plotting output using the undocumented primitives it creates.
The second option is possible by noting that the plotted GraphPlot
object has a LineStrip
object in its NodeChildren
which is responsible for drawing all the relevant edges. Because you're using a grayscale color map, the RGB data in this object is all you need to figure out how its vertices need to be ordered to get the right plot order.
First, store the plotted result in P
and set EdgeAlpha
to 1
so the graph is plotted
in such a way the lighter edges don't modify the darker when crossing them
P = plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight, 'EdgeAlpha',1);
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
Then find the LineStrip
created in the drawing process:
drawnow
s = P.NodeChildren(arrayfun(@(o) isa(o,'matlab.graphics.primitive.world.LineStrip'), P.NodeChildren));
The new order of the vertices in s
can then be determined from its ColorData
, which must then be applied to both the ColorData
and VertexData
properties to reorder the edges without anything else changing:
[~,idx] = sortrows(s.ColorData','desc');
set(s, 'VertexData',s.VertexData(:,idx), 'ColorData',s.ColorData(:,idx));
This will be liable to be overridden by any further redrawing that takes place and being undocumented functionality comes with no guarantees as to how it will behave – but superficially it seems to do what you're looking for.
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digitingP.
the automatic compilation does not showNodeChildren
yetChilden
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?
– Alberto
Mar 7 at 9:06
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.NodeChildren
is a hidden property of graphics objects andLineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods likemetaclass
to discover them.
– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
@Alberto have you been running the code above all in one go? I've realised the objects in theNodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to calldrawnow
before accessing the primitives inNodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.
– Will
Mar 8 at 9:11
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. TheGraphPlot
object has a hidden eventMarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires usingaddlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try
– Will
Mar 8 at 16:28
|
show 6 more comments
The order of the edge table in MATLAB's graph
class seems pretty tightly dependent on position in the graph's adjacency matrix, which is inherently impossible to contrive in a way that guarantees some arbitrary edge order. So I think you only have two options:
- Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.
- Manipulate MATLAB's graph plotting output using the undocumented primitives it creates.
The second option is possible by noting that the plotted GraphPlot
object has a LineStrip
object in its NodeChildren
which is responsible for drawing all the relevant edges. Because you're using a grayscale color map, the RGB data in this object is all you need to figure out how its vertices need to be ordered to get the right plot order.
First, store the plotted result in P
and set EdgeAlpha
to 1
so the graph is plotted
in such a way the lighter edges don't modify the darker when crossing them
P = plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight, 'EdgeAlpha',1);
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
Then find the LineStrip
created in the drawing process:
drawnow
s = P.NodeChildren(arrayfun(@(o) isa(o,'matlab.graphics.primitive.world.LineStrip'), P.NodeChildren));
The new order of the vertices in s
can then be determined from its ColorData
, which must then be applied to both the ColorData
and VertexData
properties to reorder the edges without anything else changing:
[~,idx] = sortrows(s.ColorData','desc');
set(s, 'VertexData',s.VertexData(:,idx), 'ColorData',s.ColorData(:,idx));
This will be liable to be overridden by any further redrawing that takes place and being undocumented functionality comes with no guarantees as to how it will behave – but superficially it seems to do what you're looking for.
The order of the edge table in MATLAB's graph
class seems pretty tightly dependent on position in the graph's adjacency matrix, which is inherently impossible to contrive in a way that guarantees some arbitrary edge order. So I think you only have two options:
- Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.
- Manipulate MATLAB's graph plotting output using the undocumented primitives it creates.
The second option is possible by noting that the plotted GraphPlot
object has a LineStrip
object in its NodeChildren
which is responsible for drawing all the relevant edges. Because you're using a grayscale color map, the RGB data in this object is all you need to figure out how its vertices need to be ordered to get the right plot order.
First, store the plotted result in P
and set EdgeAlpha
to 1
so the graph is plotted
in such a way the lighter edges don't modify the darker when crossing them
P = plot(G, 'XData', Xcoords, 'YData', Ycoords, 'NodeLabel',, 'MarkerSize', 7,...
'LineWidth', 3.8, 'EdgeCdata', G.Edges.Weight, 'EdgeAlpha',1);
colormap(flipud(gray(40)));
colorbar('southoutside'); caxis([0 1]);
axis off
Then find the LineStrip
created in the drawing process:
drawnow
s = P.NodeChildren(arrayfun(@(o) isa(o,'matlab.graphics.primitive.world.LineStrip'), P.NodeChildren));
The new order of the vertices in s
can then be determined from its ColorData
, which must then be applied to both the ColorData
and VertexData
properties to reorder the edges without anything else changing:
[~,idx] = sortrows(s.ColorData','desc');
set(s, 'VertexData',s.VertexData(:,idx), 'ColorData',s.ColorData(:,idx));
This will be liable to be overridden by any further redrawing that takes place and being undocumented functionality comes with no guarantees as to how it will behave – but superficially it seems to do what you're looking for.
edited Mar 8 at 9:12
answered Mar 6 at 11:54
WillWill
1,128617
1,128617
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digitingP.
the automatic compilation does not showNodeChildren
yetChilden
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?
– Alberto
Mar 7 at 9:06
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.NodeChildren
is a hidden property of graphics objects andLineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods likemetaclass
to discover them.
– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
@Alberto have you been running the code above all in one go? I've realised the objects in theNodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to calldrawnow
before accessing the primitives inNodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.
– Will
Mar 8 at 9:11
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. TheGraphPlot
object has a hidden eventMarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires usingaddlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try
– Will
Mar 8 at 16:28
|
show 6 more comments
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digitingP.
the automatic compilation does not showNodeChildren
yetChilden
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?
– Alberto
Mar 7 at 9:06
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.NodeChildren
is a hidden property of graphics objects andLineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods likemetaclass
to discover them.
– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
@Alberto have you been running the code above all in one go? I've realised the objects in theNodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to calldrawnow
before accessing the primitives inNodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.
– Will
Mar 8 at 9:11
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. TheGraphPlot
object has a hidden eventMarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires usingaddlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try
– Will
Mar 8 at 16:28
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digiting
P.
the automatic compilation does not show NodeChildren
yet Childen
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?– Alberto
Mar 7 at 9:06
thank you for your reply. From what I see, the only change is that now the white edge is on top the black one in the example graph with one crossing. This is due to the EdgeAlpha properties set to 1. The others lines of code seem not to change the properties. I tried inspecting the LineStrip object but it is empty, also from the command line it doesn't produce any output. Moreover, when digiting
P.
the automatic compilation does not show NodeChildren
yet Childen
. However doing as you said, it did not throw any error but it does not display the desided result. Do you know more?– Alberto
Mar 7 at 9:06
1
1
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.
NodeChildren
is a hidden property of graphics objects and LineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods like metaclass
to discover them.– Will
Mar 7 at 9:54
I misunderstood a line in your question and thought you wanted lighter colors on top. Reversing the sort order, as per my edited answer, reverses this.
NodeChildren
is a hidden property of graphics objects and LineStrip
has no public properties so your results with variable inspection are correct. You need to query hidden properties directly to see them, and use methods like metaclass
to discover them.– Will
Mar 7 at 9:54
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
I tried, but the effect does not change for the simple graph of 4 nodes... Do you know something?
– Alberto
Mar 7 at 12:33
1
1
@Alberto have you been running the code above all in one go? I've realised the objects in the
NodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to call drawnow
before accessing the primitives in NodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.– Will
Mar 8 at 9:11
@Alberto have you been running the code above all in one go? I've realised the objects in the
NodeChildren
property depend on the graph plot to have finished drawing to be initialised. I was running each stage separately from the command line, but if running all at once you need to call drawnow
before accessing the primitives in NodeChildren
. If this doesn't solve the problem, though, then you will have to do some exploration of how things work in R2017b. That's the pitfall of relying on undocumented features - there's no guarantee how things will work from on version to the next.– Will
Mar 8 at 9:11
1
1
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. The
GraphPlot
object has a hidden event MarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires using addlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try– Will
Mar 8 at 16:28
@Alberto yes, this was the kind of fragility I was worried about in the last paragraph of the answer. The
GraphPlot
object has a hidden event MarkedClean
which I think fires every time something that redraws the primitives occurs. So you could make the code that reorders the edge vertices run every time this fires using addlistener
. I'm not sure if this will disturb the zoom process at all but it's worth a try– Will
Mar 8 at 16:28
|
show 6 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55010337%2fhow-to-display-dark-edges-over-lighter-ones-in-matlab-plots%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please show a sample of how you generated the graph. It's hard to help you without seeing any reproducible code. In general though, draw the light edges first, so the dark ones can go over them.
– Mad Physicist
Mar 5 at 19:46
@MadPhysicist yes sure, I have edited the question
– Alberto
Mar 5 at 21:13
Can you show some sample code to create
G
?– Mad Physicist
Mar 5 at 21:17
Unfortunately, the graph is learning through an algorithm. I have the learned adjacency and Laplacian matrix. Do you know how to load the entire graph here?
– Alberto
Mar 5 at 21:23
You don't need to load the entire thing here, just provide a small sample with fixed data that reproduces the issue. All you need to show is a few intersecting edges.
– Mad Physicist
Mar 5 at 21:25