Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python & NetworkX 2013. 3 Youn-Hee Han

Similar presentations


Presentation on theme: "Python & NetworkX 2013. 3 Youn-Hee Han"— Presentation transcript:

1 Python & NetworkX 2013. 3 Youn-Hee Han LINK@KOREATECH http://link.koreatech.ac.kr

2 Why Python?  Python has been considered as a “godsend” to all developers.  It miraculously combines all the good things we always wanted –It is incredibly fast –It makes it easy to develop complex yet robust enterprise-level systems –It is designed to maintain clarity as development expands.  It enables “exploratory programming” LINK@KOREATECH2

3 Installing Python 2.7 & NetworkX 1.7 LINK@KOREATECH3

4 VirtualBox and Python 2.7.2  Environment Recommendation  Ubuntu in VirtualBox –In this material… Ubuntu 11.10 Python 2.7.2 LINK@KOREATECH4

5 iPython  iPython (http://ipython.org)http://ipython.org –It is an enhanced Python shell and an architecture for interactive parallel computing. –It has everything to make your Python life much easier, from tab completion to inline code inspection and interactive debugging. –In addition, IPython has a special pylab mode for matplotlib. –Terminal –Qt Console –HTML Notebook  Just run: –easy_install ipython LINK@KOREATECH5

6 NetworkX  NetworkX (http://networkx.lanl.gov/)http://networkx.lanl.gov/ –It is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.  Just run: –easy_install networkx LINK@KOREATECH6

7 numpy and matplotlib  numpy (http://networkx.lanl.gov/)http://networkx.lanl.gov/ –It is the fundamental Python package for scientific computing with Python. –It contains among other things: a powerful N-dimensional array object sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code useful linear algebra, Fourier transform, and random number capabilities  matplotlib (http://matplotlib.org/)http://matplotlib.org/ –It is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.  Just run: –easy_install numpy –easy_install matplotlib LINK@KOREATECH7

8 numpy and matplotlib  Graphic Library  backend control –http://stackoverflow.com/questions/7534453/matplotlib-does-not-show- my-drawings-although-i-call-pyplot-showhttp://stackoverflow.com/questions/7534453/matplotlib-does-not-show- my-drawings-although-i-call-pyplot-show –Location of “matplotlibrc” file /usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux- i686.egg/matplotlib/mpl-data/matplotlibrc  Just run –easy_install PyGTK  [Note] In MAC OS, you use X11 LINK@KOREATECH8 #backend : Agg backend : GTK3Agg

9 Test Code  Simple Test Code –ipython simple.py LINK@KOREATECH9 import networkx as net import matplotlib.pyplot as plt g=net.Graph() g.add_edge('a','b') net.draw(g) plt.show() simple.py

10 Test Code  Basic Animation LINK@KOREATECH10 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def update_line(num, data, line): line.set_data(data[...,:num]) return line, fig1 = plt.figure() data = np.random.rand(2, 25) l, = plt.plot([], [], 'r-') plt.xlim(0, 1) plt.ylim(0, 1) plt.xlabel('x') plt.title('test') line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), interval=50, blit=True) #line_ani.save('lines.mp4') fig2 = plt.figure() x = np.arange(-9, 10) y = np.arange(-9, 10).reshape(-1, 1) base = np.hypot(x, y) ims = [] for add in np.arange(15): ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),)) im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000, blit=True) #im_ani.save('im.mp4', metadata={'artist':'Guido'}) plt.show() basic_animation.py


Download ppt "Python & NetworkX 2013. 3 Youn-Hee Han"

Similar presentations


Ads by Google