Skip to content

Commit 144cb60

Browse files
committed
added poormans contour example
svn path=/trunk/matplotlib/; revision=332
1 parent b1b1bcc commit 144cb60

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2004-06-07 Fixed width/height issues for images - JDH
4+
35
2004-06-03 Fixed draw_if_interactive bug for semilogx;
46

57
2004-06-02 Fixed text clipping to clip to axes - JDH

examples/poormans_contour.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
"""
3+
Use a pcolor or imshow with a custom colormap to make a contour plot.
4+
A proper contour, with contour lines, is on the list of things to do
5+
"""
6+
7+
from matplotlib.matlab import *
8+
9+
10+
def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
11+
mux=0.0, muy=0.0, sigmaxy=0.0):
12+
"""
13+
Bivariate gaussan distribution for equal shape X, Y
14+
15+
http://mathworld.wolfram.com/BivariateNormalDistribution.html
16+
"""
17+
Xmu = X-mux
18+
Ymu = Y-muy
19+
20+
rho = sigmaxy/(sigmax*sigmay)
21+
z = Xmu**2/sigmax**2 + Ymu**2/sigmay - 2*rho*Xmu*Ymu/(sigmax*sigmay)
22+
return 1.0/(2*pi*sigmax*sigmay*(1-rho**2)) * exp( -z/(2*(1-rho**2)))
23+
24+
25+
delta = 0.01
26+
x = arange(-3.0, 3.0, delta)
27+
y = arange(-3.0, 3.0, delta)
28+
X,Y = meshgrid(x, y)
29+
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
30+
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
31+
32+
33+
cmap = ColormapJet(10) # 10 discrete contours
34+
im = imshow(Z2-Z1, cmap) # difference of Gaussians
35+
36+
# set the interpolation method: 'nearest', 'bilinear', 'bicubic' and much more
37+
im.set_interpolation('bilinear')
38+
39+
axis('off')
40+
#savefig('test')
41+
show()
42+

0 commit comments

Comments
 (0)