问题描述
我正在使用pygraphviz为我的项目创建图形.我无法弄清楚如何使节点的xlabel居中,以及如何更改xlabel的颜色.
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')
我尝试使用 xlp = '10,10!'
和 xlabelfontcolor ='red'
.这两个属性似乎都不起作用.我要去哪里错了.
I tried using xlp='10,10!'
and xlabelfontcolor='red'
. Both attributes don't seem to work. Where am I going wrong.
如您在附图中所见.上方,默认情况下,xlabel定位在节点的左角.同样,通过更改xlabel的颜色,可以很容易地将它与其他标签区分开,这是我无法完成的.
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.
推荐答案
无法指定外部标签的位置.(在某些时候,我们希望为此提供一些支持.)我们没有提供xlabelfontcolor属性,因为可以通过类似HTML的标签来处理该属性.确实,由于您希望外部标签居于此节点上方,因此也可以用来解决第一个问题.例如,
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
PORT属性用于使边缘在黄色框处结束.
The PORT attribute is used to get the edge to end at the yellow box.
这篇关于pygraphviz xlabel的位置和颜色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!