source: sasview/sansmodels/src/sans/models/pyre/test3d.py @ 40945a3

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 40945a3 was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 3.9 KB
Line 
1import matplotlib.pylab as pylab
2import matplotlib.axes3d as axes3d
3from matplotlib.axes3d import Axes3D
4
5# Read this: http://www.scipy.org/Cookbook/Matplotlib/mplot3D
6
7import random
8import numpy as npy
9
10
11
12def test_scatter():
13
14    fig=pylab.figure()
15    ax = Axes3D(fig)
16    #
17    #
18    n = 100
19    for c,zl,zh in [('r',-50,-25),('b',-30,-5)]:
20        xs,ys,zs = zip(*
21                       [(random.randrange(23,32),
22                         random.randrange(100),
23                         random.randrange(zl,zh)
24                         ) for i in range(n)])
25        ax.scatter3D(xs,ys,zs, c=c)
26    #
27    ax.set_xlabel('------------ X Label --------------------')
28    ax.set_ylabel('------------ Y Label --------------------')
29    ax.set_zlabel('------------ Z Label --------------------')
30
31def get_test_data(delta=0.05):
32    from matplotlib.mlab import meshgrid, bivariate_normal
33    x = y = npy.arange(-3.0, 3.0, delta)
34    X, Y = meshgrid(x,y)
35
36    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
37    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
38    Z = Z2-Z1
39
40    X = X * 10
41    Y = Y * 10
42    Z = Z * 500
43    return X,Y,Z
44
45def test_wire():
46    fig=pylab.figure()
47    ax = Axes3D(fig)
48
49    X,Y,Z = get_test_data(0.05)
50    ax.plot_wireframe(X,Y,Z, rstride=10,cstride=10)
51    #
52    ax.set_xlabel('X')
53    ax.set_ylabel('Y')
54    ax.set_zlabel('Z')
55
56def test_surface():
57    fig=pylab.figure()
58    ax = Axes3D(fig)
59
60    X,Y,Z = get_test_data(0.05)
61    ax.plot_surface(X,Y,Z, rstride=10,cstride=10)
62    #
63    ax.set_xlabel('X')
64    ax.set_ylabel('Y')
65    ax.set_zlabel('Z')
66
67
68def test_contour():
69    fig=pylab.figure()
70    ax = Axes3D(fig)
71
72    X,Y,Z = get_test_data(0.05)
73    cset = ax.contour3D(X,Y,Z)
74    ax.clabel(cset, fontsize=9, inline=1)
75    #
76    ax.set_xlabel('X')
77    ax.set_ylabel('Y')
78    ax.set_zlabel('Z')
79
80def test_plot():
81    fig=pylab.figure()
82    ax = Axes3D(fig)
83    xs = npy.arange(0,4*npy.pi+0.1,0.1)
84    ys = npy.sin(xs)
85    ax.plot(xs,ys, label='zl')
86    ax.plot(xs,ys+max(xs),label='zh')
87    ax.plot(xs,ys,dir='x', label='xl')
88    ax.plot(xs,ys,dir='x', z=max(xs),label='xh')
89    ax.plot(xs,ys,dir='y', label='yl')
90    ax.plot(xs,ys,dir='y', z=max(xs), label='yh')
91    ax.set_xlabel('X')
92    ax.set_ylabel('Y')
93    ax.set_zlabel('Z')
94    ax.legend()
95
96
97def test_polys():
98    from matplotlib.collections import LineCollection, PolyCollection
99    from matplotlib.colors import colorConverter
100
101    cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6)
102
103    fig=pylab.figure()
104    ax = Axes3D(fig)
105    xs = npy.arange(0,10,0.4)
106    verts = []
107    zs = [0.0,1.0,2.0,3.0]
108    for z in zs:
109        ys = [random.random() for x in xs]
110        ys[0],ys[-1] = 0,0
111        verts.append(zip(xs,ys))
112
113    poly = PolyCollection(verts, facecolors = [cc('r'),cc('g'),cc('b'),
114                                               cc('y')])
115    #patches = art3d.Poly3DCollectionW(poly, zs=zs, dir='y')
116    #poly = PolyCollection(verts)
117    ax.add_collection(poly,zs=zs,dir='y')
118    #ax.wrapped.add_collection(poly)
119    #
120    ax.plot(xs,ys, z=z, dir='y', c='r')
121    ax.set_xlim(0,10)
122    ax.set_ylim(-1,4)
123    ax.set_zlim(0,1)
124
125def test_scatter2D():
126    xs = [random.random() for i in range(20)]
127    ys = [random.random() for x in xs]
128    fig=pylab.figure()
129    ax = Axes3D(fig)
130    ax.scatter(xs,ys)
131    ax.scatter(xs,ys, dir='y', c='r')
132    ax.scatter(xs,ys, dir='x', c='g')
133
134def test_bar2D():
135    fig=pylab.figure()
136    ax = Axes3D(fig)
137
138    for c,z in zip(['r','g','b','y'],[30,20,10,0]):
139        xs = npy.arange(20)
140        ys = [random.random() for x in xs]
141        ax.bar(xs,ys,z=z,dir='y',color=c)
142    #ax.plot(xs,ys)
143
144if __name__ == "__main__":
145   
146    #test_scatter()
147    test_wire()
148    #test_surface()
149    #test_contour()
150    #test_plot()
151    #test_polys()
152    #test_scatter2D()
153    #test_bar2D()
154    pylab.show()
Note: See TracBrowser for help on using the repository browser.