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










3















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.
Graph










share|improve this question
























  • 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















3















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.
Graph










share|improve this question
























  • 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













3












3








3


0






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.
Graph










share|improve this question
















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.
Graph







matlab plot graph matlab-figure






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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

















  • 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
















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












1 Answer
1






active

oldest

votes


















3














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:



  1. Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.

  2. 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.






share|improve this answer

























  • 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





    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






  • 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






  • 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










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
);



);













draft saved

draft discarded


















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









3














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:



  1. Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.

  2. 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.






share|improve this answer

























  • 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





    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






  • 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






  • 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















3














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:



  1. Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.

  2. 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.






share|improve this answer

























  • 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





    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






  • 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






  • 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













3












3








3







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:



  1. Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.

  2. 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.






share|improve this answer















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:



  1. Write your own graph plotting routine; then you can control the plotting order however you like because it's your own software design.

  2. 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.







share|improve this answer














share|improve this answer



share|improve this answer








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 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





    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






  • 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






  • 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

















  • 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





    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






  • 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






  • 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
















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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved