Menu

[r3770]: / branches / mathtext_mgd / examples / simple3d_oo.py  Maximize  Restore  History

Download this file

65 lines (51 with data), 2.0 kB

 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
64
#!/usr/bin/env python
import matplotlib
matplotlib.use('WXAgg')
matplotlib.rcParams['numerix'] = 'numpy'
from wxPython.wx import *
import matplotlib.axes3d
import matplotlib.mlab
from matplotlib import numerix as nx
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, FigureManager, NavigationToolbar2WxAgg
class PlotFigure(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, "Test embedded wxFigure")
self.fig = Figure((9,8), 75)
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
self.toolbar = NavigationToolbar2WxAgg(self.canvas)
self.toolbar.Realize()
self.figmgr = FigureManager(self.canvas, 1, self)
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wxSize(fw, th))
sizer = wxBoxSizer(wxVERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW)
sizer.Add(self.toolbar, 0, wxGROW)
self.SetSizer(sizer)
self.Fit()
self.plot3d()
def plot3d(self):
# sample taken from http://www.scipy.org/Cookbook/Matplotlib/mplot3D
ax3d = matplotlib.axes3d.Axes3D(self.fig)
plt = self.fig.axes.append(ax3d)
delta = nx.pi / 199.0
u = nx.arange(0, 2*nx.pi+(delta*2), delta*2)
v = nx.arange(0, nx.pi+delta, delta)
x=nx.outerproduct(nx.cos(u),nx.sin(v))
y=nx.outerproduct(nx.sin(u),nx.sin(v))
z=nx.outerproduct(nx.ones(nx.size(u)), nx.cos(v))
print x.shape, y.shape, z.shape
#ax3d.plot_wireframe(x,y,z)
surf = ax3d.plot_surface(x, y, z)
surf.set_array(matplotlib.mlab.linspace(0, 1.0, len(v)))
ax3d.set_xlabel('X')
ax3d.set_ylabel('Y')
ax3d.set_zlabel('Z')
self.fig.savefig('globe')
if __name__ == '__main__':
app = wxPySimpleApp(0)
frame = PlotFigure()
frame.Show()
app.MainLoop()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.