Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b569e63

Browse files
committed
added new examples, other
svn path=/trunk/matplotlib/; revision=360
1 parent eeba06b commit b569e63

9 files changed

Lines changed: 494 additions & 0 deletions

File tree

examples/embedding_in_wx2.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
"""
3+
An example of how to use wx or wxagg in an application w/o the toolbar
4+
"""
5+
6+
from matplotlib.numerix import arange, sin, pi
7+
8+
import matplotlib
9+
10+
# uncomment the following to use wx rather than wxagg
11+
#matplotlib.use('WX')
12+
#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
13+
14+
# comment out the following to use wx rather than wxagg
15+
matplotlib.use('WXAgg')
16+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
17+
18+
from matplotlib.figure import Figure
19+
20+
from wxPython.wx import *
21+
22+
class CanvasFrame(wxFrame):
23+
24+
def __init__(self):
25+
wxFrame.__init__(self,None,-1,
26+
'CanvasFrame',size=(550,350))
27+
28+
self.SetBackgroundColour(wxNamedColor("WHITE"))
29+
30+
self.figure = Figure(figsize=(5,4), dpi=100)
31+
self.axes = self.figure.add_subplot(111)
32+
t = arange(0.0,3.0,0.01)
33+
s = sin(2*pi*t)
34+
35+
self.axes.plot(t,s)
36+
37+
self.canvas = FigureCanvas(self, -1, self.figure)
38+
39+
self.sizer = wxBoxSizer(wxVERTICAL)
40+
self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
41+
# Capture the paint message
42+
EVT_PAINT(self, self.OnPaint)
43+
44+
def OnPaint(self, event):
45+
self.canvas.draw()
46+
47+
class App(wxApp):
48+
49+
def OnInit(self):
50+
'Create the main window and insert the custom frame'
51+
frame = CanvasFrame()
52+
frame.Show(true)
53+
54+
return true
55+
56+
app = App(0)
57+
app.MainLoop()

examples/figimage_demo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
"""
3+
See pcolor_demo2 for a much faster way of generating pcolor plots
4+
"""
5+
from __future__ import division
6+
from matplotlib.matlab import *
7+
rc('axes', hold=True)
8+
rc('image', origin='lower')
9+
figure(1, frameon=False)
10+
Z = arange(10000.0); Z.shape = 100,100
11+
Z[:,20:] = 1
12+
jet() # sets the default
13+
im1 = figimage(Z, xo=50, yo=50) # you can also pass cmap=cm.jet as kwarg
14+
im2 = figimage(Z, xo=100, yo=100, alpha=.8)
15+
gray() # overrides current and sets default
16+
#savefig('figimage_demo')
17+
18+
show()
19+
20+

examples/image_origin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
You can specify whether images should be plotted with the array origin
3+
x[0,0] in the upper left or upper right by using the origin parameter.
4+
You can also control the default be setting image.origin in your
5+
matplotlibrc file; see http://matplotlib.sourceforge.net/.matplotlibrc
6+
"""
7+
from matplotlib.matlab import *
8+
9+
x = arange(100.0); x.shape = 10,10
10+
11+
12+
subplot(211)
13+
title('blue should be up')
14+
imshow(x, origin='upper', interpolation='nearest')
15+
16+
subplot(212)
17+
title('blue should be down')
18+
imshow(x, origin='lower', interpolation='nearest')
19+
20+
savefig('image_origin')
21+
show()

examples/scatter_profile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
N Classic Base renderer Ext renderer
3+
20 0.22 0.14 0.14
4+
100 0.16 0.14 0.13
5+
1000 0.45 0.26 0.17
6+
10000 3.30 1.31 0.53
7+
50000 19.30 6.53 1.98
8+
"""
9+
#!/usr/bin/env python
10+
from matplotlib.matlab import *
11+
12+
import time
13+
14+
15+
for N in (20,100,1000,10000,50000):
16+
tstart = time.time()
17+
x = 0.9*rand(N)
18+
y = 0.9*rand(N)
19+
s = 20*rand(N)
20+
scatter(x,y,s)
21+
#savefig('scatter_demo')
22+
print '%d symbols in %1.2f s' % (N, time.time()-tstart)

0 commit comments

Comments
 (0)