Is it possible to set an alpha value for each edge in a GraphPlot?

Colours for individual edges can be set.
% For individual edges
highlight(H, edge_idx, 'EdgeColour', [1,0,0]);
% For all edges
H.EdgeColour = % matrix with RGB-values for each edge
Opacity for all edges in the graph can be set, too.
H.EdgeAlpha = 0.01;
Unfortunately I cannot find a way to set alpha values for individual edges. Ideally, there should be a fourth channel in H.EdgeColour to control opacity.
Has anyone found a workaround?

 Accepted Answer

Hi Michael,
We do not provide a way to set EdgeAlpha to be different for each edge. We just didn't expect this to be very useful, thinking it would be hard to read these subtle differences in a graph.
For the special case where you want all edges to either have the same alpha or be completely transparent, you could instead use 'LineStyle', 'none' to make some edges completely invisible (use the highlight method for a simpler way to do this).
If you are looking for something else, could you tell me more about what you are doing? What do the different alpha's represent? Are there only a few different alpha values, or is each one slightly different?

3 Comments

I happened upon this not long after I posted this and I came to publish the solution,
I wanted to visualise a network of datacentre nodes. The nodes were linked together in a specific, tree-like way. I wanted solely to visualise the edges where errors were present and get rid of others.
If I were able to change the opacity, I would have liked to make the links with the most errors opaque and those with the fewest more transparent.
Perhaps it would be helpful for visualisation if the option were there.
I did find, however, that in order to set line-styles for each edge, one must first initialise the line-styles for every edge. Perhaps this was meant to save time.
The LineStyle property is a scalar by default, this was done to simplify the workflow of setting all edges to the same LineStyle.
The highlight method allows setting the style for a subset of the edges, and will automatically initialize a cell array with one entry for each edge.
p = plot(graph(1, [2 3]));
highlight(p, 1, 3, 'LineStyle', '--')
I am very surprised that you don't see a use case in assigning alpha to individual edges. As a systems ecologist I often create figures for publications with complex geographic networks. Setting alpha of low weight connections is extremely useful. Right now I get around this with custom code that avoides using digraphs all together, which is unfortunate.

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!