Ticket #396: test2.py

File test2.py, 1.2 KB (added by Nick Draper, 12 years ago)
Line 
1# plotting with the pylab module from matplotlib
2# free from: http://matplotlib.sourceforge.net/
3# used windows istaller matplotlib-0.90.0.win32-py2.5.exe
4# tested with Python25 EU 4/21/2007
5       
6import math
7import pylab # matplotlib
8
9# create the x list data
10# arange() is just like range() but allows float numbers
11x_list = pylab.arange(0.0, 5.0, 0.01)
12
13# calculate the y list data
14y_list = []
15for x in x_list:
16        y = math.cos(2*math.pi*x) * math.exp(-x)
17        y_list.append(y)
18       
19pylab.xlabel("x")
20pylab.ylabel("cos(2pi * x) * exp(-x)")
21       
22# draw the plot with a blue line 'b' (is default)
23# using x,y data from the x_list and y_list
24# (these lists can be brought in from other programs)
25#
26# other drawing styles -->
27# 'r' red line, 'g' green line, 'y' yellow line
28# 'ro' red dots as markers, 'r.' smaller red dots, 'r+' red pluses
29# 'r--' red dashed line, 'g^' green triangles, 'bs' blue squares
30# 'rp' red pentagons, 'r1', 'r2', 'r3', 'r4' well, check out the markers
31#
32pylab.plot(x_list, y_list, 'b')
33       
34# save the plot as a PNG image file (optional)
35pylab.savefig('Fig1.png')
36     
37# show the pylab plot window
38# you can zoom the graph, drag the graph, change the margins, save the graph
39pylab.show()