|
6 | 6 | #npts = int(raw_input('enter # of random points to plot:')) |
7 | 7 | seed(0) |
8 | 8 | npts = 200 |
9 | | -x = uniform(-2,2,npts) |
10 | | -y = uniform(-2,2,npts) |
11 | | -z = x*np.exp(-x**2-y**2) |
| 9 | +x = uniform(-2, 2, npts) |
| 10 | +y = uniform(-2, 2, npts) |
| 11 | +z = x*np.exp(-x**2 - y**2) |
12 | 12 | # define grid. |
13 | | -xi = np.linspace(-2.1,2.1,100) |
14 | | -yi = np.linspace(-2.1,2.1,200) |
| 13 | +xi = np.linspace(-2.1, 2.1, 100) |
| 14 | +yi = np.linspace(-2.1, 2.1, 200) |
15 | 15 | # grid the data. |
16 | | -zi = griddata(x,y,z,xi,yi,interp='linear') |
| 16 | +zi = griddata(x, y, z, xi, yi, interp='linear') |
17 | 17 | # contour the gridded data, plotting dots at the nonuniform data points. |
18 | | -CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') |
19 | | -CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.rainbow, |
| 18 | +CS = plt.contour(xi, yi, zi, 15, linewidths=0.5, colors='k') |
| 19 | +CS = plt.contourf(xi, yi, zi, 15, cmap=plt.cm.rainbow, |
20 | 20 | vmax=abs(zi).max(), vmin=-abs(zi).max()) |
21 | | -plt.colorbar() # draw colorbar |
| 21 | +plt.colorbar() # draw colorbar |
22 | 22 | # plot data points. |
23 | | -plt.scatter(x,y,marker='o',c='b',s=5,zorder=10) |
24 | | -plt.xlim(-2,2) |
25 | | -plt.ylim(-2,2) |
| 23 | +plt.scatter(x, y, marker='o', c='b', s=5, zorder=10) |
| 24 | +plt.xlim(-2, 2) |
| 25 | +plt.ylim(-2, 2) |
26 | 26 | plt.title('griddata test (%d points)' % npts) |
27 | 27 | plt.show() |
28 | | - |
29 | | -# test case that scikits.delaunay fails on, but natgrid passes.. |
30 | | -#data = np.array([[-1, -1], [-1, 0], [-1, 1], |
31 | | -# [ 0, -1], [ 0, 0], [ 0, 1], |
32 | | -# [ 1, -1 - np.finfo(np.float_).eps], [ 1, 0], [ 1, 1], |
33 | | -# ]) |
34 | | -#x = data[:,0] |
35 | | -#y = data[:,1] |
36 | | -#z = x*np.exp(-x**2-y**2) |
37 | | -## define grid. |
38 | | -#xi = np.linspace(-1.1,1.1,100) |
39 | | -#yi = np.linspace(-1.1,1.1,100) |
40 | | -## grid the data. |
41 | | -#zi = griddata(x,y,z,xi,yi) |
0 commit comments