问题
I am using pygraphviz to create graphs for my project. I am unable to figure out how to center the xlabel of nodes and also how to change the color of xlabel.
graph.add_node(row[3], color='goldenrod2', style='filled', shape='box',
xlabel=round(self.pi_dict.get(row[3]), 2), fontname='calibri')
I tried using xlp='10,10!'
and xlabelfontcolor='red'
. Both attributes don't seem to work. Where am I going wrong.
As you can see in the attached fig. above, the xlabel is positioned by default towards the left corner of the nodes. Also by changing the color of xlabel, it can be easily distinguished from other labels, which I am unable to accomplish.
回答1:
There is no way to specify the position of an external label. (At some point, we hope to provide some support for this.) We didn't provide an xlabelfontcolor attribute as this can be handled via HTML-like labels. Indeed, since you want the external label centered above this node, this can also be used to solve your first problem. For example,
a [shape=none label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
<TR><TD><FONT COLOR="red">0.19</FONT></TD></TR>
<TR><TD CELLPADDING="6" BGCOLOR="goldenrod2" PORT="p1">would</TD></TR></TABLE>>]
b -> a:p1:n
The PORT attribute is used to get the edge to end at the yellow box.
来源:https://stackoverflow.com/questions/16265541/pygraphviz-xlabel-position-and-color-doesnt-work