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

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

问题描述

我使用networkX和matplotlib绘制了一个大约5K节点的图。 matplotlib提供的GTK窗口具有缩放和可视化图形的工具。
有没有办法,我可以保存一个放大版本,以便以后可以正确显示?

  import matplotlib.pyplot as plt 
import networkx as nx

pos = nx.spring_layout(G)#G是我的图

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)


> DPI



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


$ b

(较大图片文件大小)

另存为PDF



  plt.savefig(graph.pdf)

这是最好的选择,因为最终的图不是光栅化的。理论上,您应该可以无限放大。

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) 

解决方案

You have two easy options:

Up the DPI

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

(larger image file size)

Save as a PDF

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天全站免登陆