如何解决在 MatPlotLib 中向 NetworkX 图形添加填充
我想用 networkx
渲染一个 matplotlib
图。标签有点长(每个大约 10 - 50 个字符),而且它们往往会被切断,使我无法阅读它们。有没有办法让 matplotlib “缩小”最终渲染,以便我可以阅读所有文本?
下面是我的代码以及渲染图。
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
root_node = 'this is the root node'
G.add_node(root_node)
for other_node in [
'test is an adjacent node','test is another adjacent node','test is yet another adjacent node','test is the fourth adjacent node',]:
G.add_node(other_node)
G.add_edge(root_node,other_node)
nx.draw(G,with_labels=True,font_size=8,node_color='white')
plt.show()
解决方法
看起来像创建一个轴并在其上设置边距做到了:
ax1 = plt.subplot(111)
ax1.margins(0.3)
nx.draw(
G,ax=ax1,with_labels=True,font_size=8,node_color='white',)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。