forked from treverhines/tplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axes3d.py~
63 lines (50 loc) · 1.59 KB
/
axes3d.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
from misc import rotation3D
from mpl_toolkits.mplot3d import Axes3D as _Axes3D
from matplotlib import cm
import numpy as np
import tcmap
class Axes3D(_Axes3D):
def __init__(self,*args,**kwargs):
if (len(args) > 1) | kwargs.has_key('rect'):
_Axes3D.__init__(self,*args,**kwargs)
else:
rect = (0.1,0.1,0.8,0.8)
_Axes3D.__init__(self,*args,rect=rect,**kwargs)
def cross_section(self,func,anchor,
zrot,yrot,xrot,
length,width,
Nl=20,Nw=20,
cmap=tcmap.slip,
clim=None):
x = np.linspace(0,length,Nl)
y = np.linspace(0,-width,Nw)
x,y = np.meshgrid(x,y)
z = 0.0*x
R = rotation3D(zrot,yrot,xrot)
p = np.concatenate((x[None,:,:],
y[None,:,:],
z[None,:,:]),
axis=0)
p = np.einsum('ij,jkl->kli',R,p)
p += anchor
x = p[:,:,0]
y = p[:,:,1]
z = p[:,:,2]
c = f(x,y,z)
if clim is None:
clim = (np.min(c),np.max(c))
cnorm = (c - clim[0])/(clim[1] -clim[0])
s = self.plot_surface(x,y,z,
shade=False,
facecolors=cmap(cnorm),
rstride=1,cstride=1)
m = cm.ScalarMappable(cmap=cmap)
m.set_array(c)
idx1 = np.array([[0,-1],[0,-1]])
idx2 = np.array([[0,0],[-1,-1]])
w = self.plot_wireframe(x[idx1,idx2],
y[idx1,idx2],
z[idx1,idx2],
color='k')
return m