用命题的形式调整Netgraph中的字体大小?
我正在使用NetGraph可视化我的网络图。我现在的问题是,公式的可视化自然方式不像我预期的那样漂亮。这里我的示例图:
import networkx as nx
from netgraph import Graph # pip install netgraph
import matplotlib.pyplot as plt
node_labels = {1: 'p→q', 2: '¬q', 3: '¬ (¬p)', 4: '¬p', 5: '¬p∧ ¬ (¬p)', 6: 'p', 7: 'q', 8: 'q∧ ¬q', 9: '¬p'}
color_map = {1: 'red', 2: 'red', 3: 'red', 4: 'red', 5: 'lightblue', 6: 'lightblue', 7: 'lightblue', 8: 'lightblue', 9: 'blue'}
edge_labels = {(3, 5): '∧I', (4, 5): '∧I', (4, 6): '¬E', (5, 6): '¬E', (1, 7): '→E', (6, 7): '→E', (2, 8): '∧I', (7, 8): '∧I', (8, 9): '¬E', (3, 9): '¬E'}
graph = nx.from_edgelist(edge_labels, nx.DiGraph())
Graph(graph, node_labels=node_labels, edge_labels=edge_labels,
node_color=color_map, node_edge_color=color_map, arrows=True)
plt.show()
输出(Direct/Zoom in):
我现在的问题:
- 它们是否是调整节点字体大小的方法?
- 是否可以以这种方式旋转边缘标签?
I am using netgraph to visualize my networkx graphs. My problem now is, the visualisation of formulas are in natural way not as pretty as I would expect. Here my example graph:
import networkx as nx
from netgraph import Graph # pip install netgraph
import matplotlib.pyplot as plt
node_labels = {1: 'p→q', 2: '¬q', 3: '¬ (¬p)', 4: '¬p', 5: '¬p∧ ¬ (¬p)', 6: 'p', 7: 'q', 8: 'q∧ ¬q', 9: '¬p'}
color_map = {1: 'red', 2: 'red', 3: 'red', 4: 'red', 5: 'lightblue', 6: 'lightblue', 7: 'lightblue', 8: 'lightblue', 9: 'blue'}
edge_labels = {(3, 5): '∧I', (4, 5): '∧I', (4, 6): '¬E', (5, 6): '¬E', (1, 7): '→E', (6, 7): '→E', (2, 8): '∧I', (7, 8): '∧I', (8, 9): '¬E', (3, 9): '¬E'}
graph = nx.from_edgelist(edge_labels, nx.DiGraph())
Graph(graph, node_labels=node_labels, edge_labels=edge_labels,
node_color=color_map, node_edge_color=color_map, arrows=True)
plt.show()
Output (direct / after zoom in):
My questions now:
- Is their a way to adjust the font size of the nodes?
- Is it possible to rotate the edge labels in that way they are aligned horizontally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,iff节点标签绘制在节点顶部(即没有偏移),NetGraph缩放节点标签字体大小,以使所有标签都适合其各自的节点艺术家。但是,可以通过明确指定字体大小,例如使用
node_label_fontdict(size = 20)
来覆盖此行为。边缘标签的旋转可以关闭设置
edge_label_rotate = false
flag。By default, iff node labels are plotted on top of nodes (i.e. without an offset), netgraph scales the node label font size such that all labels fit within their respective node artists. However, this behaviour can be overridden by specifying the font size explicitly , e.g. using
node_label_fontdict(size=20)
.The rotation of the edge labels can be turned off setting the
edge_label_rotate = False
flag.Plotly具有a 网络图的非常好的示例很容易根据您的需求阅读。
这是您任务的答案。
导致:

编辑:
用plotly添加边缘说明更加棘手(请参阅此问题)。幸运的是,有一个 github project 我们可以从中借用一个函数,通过保持箭头来通过保持边缘来保持边缘来保持边缘。考虑到节点大小。
现在的代码为:
产生:
Plotly has a very nice example of network graph that can be easily readapted to your needs.
Here's the answer to your quests.
Resulting in:

Edit:
Adding edges directions with Plotly is a bit more tricky (see this question). Fortunately there is a github project from which we can borrow a function that adds arrowheads to edges by keeping into account node sizes.
The code now is:
Resulting in: