1 / 10

Python & NetworkX

Python & NetworkX. 2013. 3 Youn-Hee Han LINK@KOREATECH http://link.koreatech.ac.kr. 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

Download Presentation

Python & NetworkX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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@KOREATECH

  3. Installing Python 2.7 & NetworkX 1.7 LINK@KOREATECH

  4. VirtualBox and Python 2.7.2 • Environment Recommendation  Ubuntu in VirtualBox • In this material… • Ubuntu 11.10 • Python 2.7.2 LINK@KOREATECH

  5. iPython • iPython (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@KOREATECH

  6. NetworkX • NetworkX (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@KOREATECH

  7. numpy and matplotlib • numpy (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/) • 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@KOREATECH

  8. numpy and matplotlib • Graphic Library  backend control • http://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 • #backend : Agg • backend : GTK3Agg LINK@KOREATECH

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

  10. Test Code basic_animation.py • Basic Animation • 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() LINK@KOREATECH

More Related