Control edge alpha via edge weights to visualize a dynamic network

15 visualizaciones (últimos 30 días)
My Goal:
I use digraph to visualize a chemical reaction network. The nodes are chemical complexes and the edges are the chemical reactions. For each chemical reaction (i.e., edge) I assign a weight that represents the (normalized) rate of the respective chemical reaction. Thus, the weights can have values in [0,1], where 0 identifies an inactive reaction and 1 the fastest reaction.
The weights (i.e. the rates of the chemical reactions) change over the reaction time. Therefore, a reaction that was initially inactive (weight = 0) can become active (weight > 0) and vice versa. I want to visualize the course of the chemical reaction by plotting three graphs (beginning, middle and end of the reaction time). I map the edge weights to the edge line widths, so that a fast reaction has a thicker line width than a slower reaction.
My Problem:
In the case where a reaction is inactive, its edge weight is zero. Since the line width has to be positive, this results in an error. Currently I circumvent this by adding a small positive number to the line width. This works but it is misleading because inactive reactions are displayed in the graph. Removing the inactive reactions first would be another idea. However, this changes the network and thus it becomes difficult to compare the three graphes along the reaction time (beginning, middle, end).
Therefore, ideally I would want to control the alpha value of the individual edges via the weights. However, it seems that this is not supported.
Do you have any other idea on how to tackle this problem? Thank you very much. Any help is much appreciated!

Respuesta aceptada

Christine Tobler
Christine Tobler el 28 de En. de 2020
Editada: Christine Tobler el 29 de En. de 2020
You can set the LineStyle to be 'none' for edges that should not be displayed:
>> g = digraph([3 1 2], [2 3 1], [0 0.5 1]);
>> p = plot(g, 'LineWidth', max(5*g.Edges.Weight, 1));
>> highlight(p, 'Edges', find(g.Edges.Weight == 0), 'LineStyle', 'none');
Unfortunately, EdgeAlpha is a scalar property, which can't be set to different values for each edge.
Alternatively, you could use 'EdgeCData' to represent each edge's value with a different color:
>> plot(g, 'EdgeCData', g.Edges.Weight, 'LineWidth', 3);
>> colorbar
>> colormap(flip(gray))
Here I've set up the color map such that an edge with zero weight is shown as white. As long as the background is white and there aren't too many edges intersecting, this will look the same as if the edge had disappeared.

Más respuestas (0)

Categorías

Más información sobre Chemistry en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by