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 | |
---|
6 | import math |
---|
7 | import pylab # matplotlib |
---|
8 | |
---|
9 | # create the x list data |
---|
10 | # arange() is just like range() but allows float numbers |
---|
11 | x_list = pylab.arange(0.0, 5.0, 0.01) |
---|
12 | |
---|
13 | # calculate the y list data |
---|
14 | y_list = [] |
---|
15 | for x in x_list: |
---|
16 | y = math.cos(2*math.pi*x) * math.exp(-x) |
---|
17 | y_list.append(y) |
---|
18 | |
---|
19 | pylab.xlabel("x") |
---|
20 | pylab.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 | # |
---|
32 | pylab.plot(x_list, y_list, 'b') |
---|
33 | |
---|
34 | # save the plot as a PNG image file (optional) |
---|
35 | pylab.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 |
---|
39 | pylab.show() |
---|