用 networkX 和 matplotlib 绘制一个巨大的图形 [英] Drawing a huge graph with networkX and matplotlib

查看:29
本文介绍了用 networkX 和 matplotlib 绘制一个巨大的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 networkX 和 matplotlib 绘制一个包含大约 5K 个节点的图形.matplotlib 的 GTK 窗口具有缩放和可视化图形的工具.有没有什么办法,我可以保存一个放大的版本,以便稍后进行适当的可视化?

I am drawing a graph with around 5K nodes in it using networkX and matplotlib. The GTK window by matplotlib has tools to zoom and visualise the graph. Is there any way, I can save a magnified version for proper visualisation later?

import matplotlib.pyplot as plt
import networkx as nx

pos=nx.spring_layout(G)   #G is my graph

nx.draw(G,pos,node_color='#A0CBE2',edge_color='#BB0000',width=2,edge_cmap=plt.cm.Blues,with_labels=True)
#plt.show()
plt.savefig("graph.png", dpi=500, facecolor='w', edgecolor='w',orientation='portrait', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.1) 

推荐答案

您有两个简单的选择:

plt.savefig("graph.png", dpi=1000)

(较大的图像文件大小)

(larger image file size)

plt.savefig("graph.pdf")

这是最好的选择,因为最终的图形没有被光栅化.理论上,您应该能够无限放大.

This is the best option, as the final graph is not rasterized. In theory, you should be able to zoom in indefinitely.

这篇关于用 networkX 和 matplotlib 绘制一个巨大的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆