Skip to content

Commit c843221

Browse files
committed
updated image demo examples
svn path=/trunk/matplotlib/; revision=182
1 parent 85d9a95 commit c843221

File tree

3 files changed

+136
-12
lines changed

3 files changed

+136
-12
lines changed

examples/image_demo.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
from matplotlib.matlab import *
22

3-
w, h = 512, 512
4-
s = file('data/ct.raw', 'rb').read()
5-
A = fromstring(s, typecode=UInt16).astype(Float)
6-
A *= 1.0/max(A)
7-
A.shape = w,h
8-
im = imshow(A)
9-
10-
# set the interpolation method: 'nearerst', 'bilinear', 'bicubic' and much more
3+
4+
def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
5+
mux=0.0, muy=0.0, sigmaxy=0.0):
6+
"""
7+
Bivariate gaussan distribution for equal shape X, Y
8+
9+
http://mathworld.wolfram.com/BivariateNormalDistribution.html
10+
"""
11+
Xmu = X-mux
12+
Ymu = Y-muy
13+
14+
rho = sigmaxy/(sigmax*sigmay)
15+
z = Xmu**2/sigmax**2 + Ymu**2/sigmay - 2*rho*Xmu*Ymu/(sigmax*sigmay)
16+
return 1.0/(2*pi*sigmax*sigmay*(1-rho**2)) * exp( -z/(2*(1-rho**2)))
17+
18+
def normz(Z):
19+
'constrain array to be in 0,1'
20+
minz = min(min(Z))
21+
maxz = max(max(Z))
22+
return 1.0/(maxz-minz)*(Z-minz)
23+
24+
delta = 0.025
25+
x = arange(-3.0, 3.0, delta)
26+
y = arange(-3.0, 3.0, delta)
27+
X,Y = meshgrid(x, y)
28+
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
29+
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
30+
31+
# difference of Gaussians
32+
im = imshow(normz(Z2-Z1))
33+
34+
# set the interpolation method: 'nearest', 'bilinear', 'bicubic' and much more
1135
im.set_interpolation('bilinear')
1236

13-
# aspect ratio 'free' or 'preserve'
14-
im.set_aspect('preserve')
1537

1638
axis('off')
17-
title('CT density')
39+
savefig('test')
1840
show()
1941

examples/simple_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
xlabel('time (s)')
99
ylabel('voltage (mV)')
1010
title('About as simple as it gets, folks')
11-
grid(True)
11+
#grid(True)
1212
#savefig('simple_plot',dpi=300)
1313
show()

postinstall.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"""
2+
See for example
3+
http://www.geocrawler.com/archives/3/14884/2002/10/0/9979630/
4+
5+
6+
"""
7+
8+
s = r"""#### MATPLOTLIBRC FORMAT
9+
# This is a sample matplotlib configuration file
10+
# It should be placed in your home dir (Linux and friends) or
11+
# in the matplotlib data path, is, where matplotlib installs it's
12+
# data files (fonts, etc). On windows, this would be, for example,
13+
# C:\Python23\share\matplotlib
14+
#
15+
# This file is best viewed in a editor which supports python mode
16+
# syntax highlighting
17+
#
18+
# Blank lines, or lines starting with a comment symbol, are ignored,
19+
# as are trailing comments. Other lines must have the format
20+
#
21+
# key : val # optional comment
22+
#
23+
# Colors: for the color values below, you can either use
24+
# - a matplotlib color string, such as r, k, or b
25+
# - an rgb tuple, such as (1.0, 0.5, 0.0)
26+
# - a hex string, such as ff00ff (no '#' symbol)
27+
# - a scalar grayscale intensity such as 0.75
28+
29+
#### CONFIGURATION BEGINS HERE
30+
backend : GTK # the default backend
31+
numerix : numeric # Numeric or numarray
32+
interactive : False # see http://matplotlib.sourceforge.net/interactive.html
33+
34+
### LINES
35+
# See http://matplotlib.sourceforge.net/matplotlib.lines.html for more
36+
# information on line properties. Note antialiased rendering looks
37+
# better, but can be slower. If you want fast antialiased rendering,
38+
# use the agg backend (or TkAgg, or GTKAgg)
39+
lines.linewidth : 0.5 # line width in points
40+
lines.linestyle : - # solid line
41+
lines.color : b # blue; color format or hex string
42+
lines.markersize : 6 # markersize, in points
43+
lines.antialiased : True # render lines in antialised (no jaggies)
44+
lines.data_clipping : False # Use data clipping in addition to viewport
45+
# clipping. Useful if you plot long data
46+
# sets with only a fraction in the viewport
47+
48+
### TEXT
49+
# text properties used by text.Text. See
50+
# http://matplotlib.sourceforge.net/matplotlib.Text.html for more
51+
# information on text properties
52+
text.fontname : Times # default font name
53+
text.fontsize : 10 # default size used by axes.text
54+
text.color : k # black
55+
56+
### AXES
57+
# default face and edge color, default tick sizes,
58+
# default fontsizes for ticklabels, and so on
59+
axes.facecolor : w # background color; white
60+
axes.edgecolor : k # edge color; black
61+
axes.linewidth : 1.0 # edge linewidth
62+
axes.grid : False # display grid or not
63+
axes.titlesize : 14 # fontsize of the axes title
64+
axes.labelsize : 12 # fontsize of the x any y labels
65+
axes.labelcolor : k # black
66+
67+
### TICKS
68+
tick.size : 4 # tick size in points
69+
tick.color : k # color of the tick labels
70+
tick.labelsize : 10 # fontsize of the tick labels
71+
72+
### FIGURE
73+
figure.figsize : 8, 6 # figure size in inches
74+
figure.dpi : 80 # figure dots per inch
75+
figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray
76+
figure.edgecolor : w # figure edgecolor; w is white
77+
78+
### SAVING FIGURES
79+
# the default savefig params can be different for the GUI backends.
80+
# Eg, you may want a higher resolution, or to make the figure
81+
# background white
82+
savefig.dpi : 100 # figure dots per inch
83+
savefig.facecolor : w # figure facecolor; 0.75 is scalar gray
84+
savefig.edgecolor : w # figure edgecolor; w is white
85+
86+
"""
87+
import sys, os
88+
import distutils.sysconfig
89+
90+
if sys.platform[:3] != 'win':
91+
sys.exit()
92+
93+
target = os.path.join(distutils.sysconfig.PREFIX,
94+
'share', 'matplotlib', '.matplotlibrc')
95+
if not os.path.exists(target):
96+
97+
print 'Writing %s' % target
98+
file(target, 'w').write(s)
99+
file_created(target)
100+
else:
101+
print 'matplotlibrc file %s already exists' % target
102+

0 commit comments

Comments
 (0)