How can I draw a bicolor edge?
Clash Royale CLAN TAG#URR8PPP
How can I draw a bicolor edge?
I'm currently trying to represent a graph with Graphviz, in which the edges have 2 colors. Ideally, I'd like to have each edge cut in two, one half colored in each color.
Another constraint is that I have to use the RGB encoding, like in color="#4a52ff"
. I can't use the color="black"
way.
color="#4a52ff"
color="black"
I've tried to separe the color tags with a :
, but the result I obtain is a double edge.
:
Here is a minimal example :
import graphviz as gv
color1, color2 = "#3f7f3f", "#ff7f3f"
g = gv.Graph(format="png")
g.node("1", color=color1)
g.node("2", color=color2)
g.edge("1", "2", color="%s:%s" % (color1, color2))
g.render("tmp", view=True)
I obtain a small graph with 2 nodes and 1 edge, but the single edge seems to have been doubled, one version in each color.
What I'd like to have is one orange end, connected to the orange node, and one green end connected to the green one.
2 Answers
2
From the Node, Edge and Graph Attributes - color page, Graphviz supports the coloring of edges if you specify a fraction.
This supports the common case of drawing opposing edges, but using parallel splines instead of separately routed multiedges. If any fraction is used, the colors are drawn in series, with each color being given roughly its specified fraction of the edge.
In your case change the following line:
g.edge("1", "2", color="%s:%s" % (color1, color2))
to:
g.edge("1", "2", color="%s;%f:%s" % (color1, 0.5, color2))
And it renders like this:
The closest I can come to what you want is by introducing a node in between:
graph g
mid [shape=point ];
node1 [ color = "#3f7f3f"];
node2 [ color = "#ff7f3f"];
node1 -- mid [ color= "#3f7f3f"];
mid -- node2 [color = "#ff7f3f"];
This yields a result similar to what you describe:
Now, I'm just using GraphViz and you're using the python version, but the key here, if you choose to use it, is the intermediate node with the other node colors reaching to it.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.