如何用ipython表示图形 [英] How to represent graphs with ipython

查看:140
本文介绍了如何用ipython表示图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我发现了 ipython notebook 这是一个强大的工具。作为一名IT学员,我一直在等待用Python代表图表。例如,我想知道是否有一个库(如 numpy matplotlib ?)

  {1:[3,2],
2:[4 ],
3:[6],
4:[​​6],
5:[7,8],
6:[],
7:[],
8:[]
}

像这样:



有没有这样的事情?

解决方案

您可以使用 networkx ,如果您需要呈现ipython笔记本中的图表, nxpd

  import networkx as nx 
from nxpd import draw
G = nx.DiGraph()
G.graph ['dpi'] = 120
G .add_nodes_from(range(1,9))
G.add_edges_from([(1,2),(1,3),(2,4),(3,6),(4, 5),(4,6),(5,7),(5,8)])
draw(G,show ='ipynb')


Recently I discovered ipython notebook which is a powerful tool. As an IT student, I was looking for a wait to represent graphs in Python. For exemple, I would like to know if there's a library (like numpy or matplotlib ?) which can draw from this

{ "1" : ["3", "2"],
  "2" : ["4"],
  "3" : ["6"],
  "4" : ["6"],
  "5" : ["7", "8"],
  "6" : [],
  "7" : [],
  "8" : []
}

something like this :

Is there something like this ?

解决方案

You can use networkx and, if you need to render the graph in ipython notebook, nxpd

import networkx as nx
from nxpd import draw
G = nx.DiGraph()
G.graph['dpi'] = 120
G.add_nodes_from(range(1,9))
G.add_edges_from([(1,2),(1,3),(2,4),(3,6),(4,5),(4,6),(5,7),(5,8)])
draw(G, show='ipynb')

这篇关于如何用ipython表示图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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