matplotlib-installatin-interactive-contour-example-guide
Upcoming SlideShare
Loading in...5
×
 

matplotlib-installatin-interactive-contour-example-guide

on

  • 4,905 views

 

Statistics

Views

Total Views
4,905
Views on SlideShare
2,650
Embed Views
2,255

Actions

Likes
0
Downloads
12
Comments
0

4 Embeds 2,255

http://tuxworld.wordpress.com 2225
http://www.slideshare.net 23
http://translate.googleusercontent.com 4
url_unknown 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

matplotlib-installatin-interactive-contour-example-guide matplotlib-installatin-interactive-contour-example-guide Document Transcript

  • Matplotlib Installation Guide Hi This guide will help to install matplotlib those who are all newbie to python and source installation. Ref : http://matplotlib.sourceforge.net/users/installing.html To install matplotlib , we need to 4 major depencies which are , 1) python 2.4 (or later but not python3) matplotlib requires python 2.4 or later $ sudo apt-get install python 2) numpy 1.1 (or later) array support for python Download the source of numpy from here http://sourceforge.net/projects/numpy/files/NumPy/ untar the source using command $ tar zxvf filename.tar.gz or Right click the tarball package and click on the ” Extract here ” . $ cd numpy-1.4.0 # i used to setup numpy $ python setup.py build $ sudo python setup.py install 3) libpng 1.1 (or later) library for loading and saving PNG files. Download the source of libpng from here http://www.libpng.org/pub/png/libpng.html untar the source $ cd libpng-1.2.41 # i used to setup libpng $ ./configure $ make $ sudo make install 4) freetype 1.4 (or later) library for reading true type font files. Download the source of freetype from here http://www.freetype.org/ untar the source $ cd freetype-2.3.9 # i used to setup libpng $ ./configure $ make $ sudo make install Now Download the source of matplotlib from http://sourceforge.net/projects/matplotlib/files/
  • Install it by the following way . untar the source $ cd matplotlib-0.99.1.2 # i used to setup matplotlib $ python setup.py build $ sudo python setup.py install Thats all. we installed matplotlib successfully . I installed all the above setup in ubuntu 9.10 , working perfectly ! Interactive contour in matplotib Interactive contour in matplotib , eg 1: #begin of code from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt import numpy as np import time plt.ion()  #interactive on fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contourf(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) plt.draw() ans='' while ans != 'q': ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contourf(X, Y, Z) ans=raw_input('enter level values or 'q' to quit : ') #for eg : cset.level=[-45,-30,-20,-10,0,10,15,30,45,60] cset = ax.contourf(X, Y, Z,cset.levels) ax.clabel(cset, fontsize=9, inline=1)
  • plt.draw() time.sleep(3) plt.clf() plt.ioff()    #interactive off plt.close() #End of code The above python program will run the contour 3D view using matplotlib. And we can give the input at run time to change the contour levels. while running the above program , in prompt says like “enter level values or ‘q’ to quit:” Enter the following [-45,-30,-20,-10,0,10,15,30,45,60] and press Enter . Now u can see the changes of contour levels in the same figure. so u can give the various levles of contour. ( upto 10 levels ‘default’) Enter ‘q’ to quit the interaction mode. Interactive in matplotib , eg 2: Using file save the following contour levels values in list manner and save it as “contour.txt” contour.txt [-45,-30,-20,-10,0,10,15,30] [-55,-25,-15,2,8,40,50,78] [-40,-15,-10,1,20,49,60] [-35,-28,-15,0,10,20,40] matplotlib.py #begin of code from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt import numpy as np import time plt.ion() f1 = open(r'contour.txt') fig = plt.figure() ax = axes3d.Axes3D(fig)
  • X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) ax.view_init(0, 30) #(0,30) side view #(90,0) top view ans='' plt.draw() raw_input('enter') plt.ion() for ans in f1.readlines(): ax = axes3d.Axes3D(fig) ax.view_init(0, 30) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z) cset.levels=eval(ans.strip()) print cset.levels cset = ax.contour(X, Y, Z,cset.levels) ax.clabel(cset, fontsize=9, inline=1) plt.draw() time.sleep(3) raw_input('enter') plt.clf() plt.close() f1.close() #end of code Run the above python coding. It will take the input contour levels from the file “contour.txt” and the output shows like movie of 3d contour changes in its levels. Outputs :
  • Initial levels in 3D contour : [ fill ] code : ax.contourf(X, Y, Z,cset.levels)
  • Changes in contour levels :
  • Contour in Line Drawing : code : ax.contour(X, Y, Z,cset.levels)
  • Changes in Line contour levels :
  • Contour in Top View : code : ax.view_init(90, 0)
  • Contour level changes in top view :
  • Contour in side view : code : ax.view_init(0, 30)
  • Contour changes in side view : By this way , we can interact with contour 3D plot using matplotlb . By , Arulalan.T