|
62 | 62 | CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) |
63 | 63 |
|
64 | 64 |
|
65 | | -#savefig('contour_demo') |
66 | | -plt.show() |
67 | | -#!/usr/bin/env python |
68 | | -""" |
69 | | -Illustrate simple contour plotting, contours on an image with |
70 | | -a colorbar for the contours, and labelled contours. |
71 | | -
|
72 | | -See also contour_image.py. |
73 | | -""" |
74 | | -import matplotlib |
75 | | -import numpy as np |
76 | | -import matplotlib.cm as cm |
77 | | -import matplotlib.mlab as mlab |
78 | | -import matplotlib.pyplot as plt |
79 | | - |
80 | | -matplotlib.rcParams['xtick.direction'] = 'out' |
81 | | -matplotlib.rcParams['ytick.direction'] = 'out' |
82 | | - |
83 | | -delta = 0.025 |
84 | | -x = np.arange(-3.0, 3.0, delta) |
85 | | -y = np.arange(-2.0, 2.0, delta) |
86 | | -X, Y = np.meshgrid(x, y) |
87 | | -Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
88 | | -Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
89 | | -# difference of Gaussians |
90 | | -Z = 10.0 * (Z2 - Z1) |
91 | | - |
92 | | - |
93 | | -# You can use a colormap to specify the colors; the default |
94 | | -# colormap will be used for the contour lines |
95 | | -plt.figure() |
96 | | -im = plt.imshow(Z, interpolation='bilinear', origin='lower', |
97 | | - cmap=cm.gray, extent=(-3,3,-2,2)) |
98 | | -levels = np.arange(-1.2, 1.6, 0.2) |
99 | | -CS = plt.contour(Z, levels, |
100 | | - origin='lower', |
101 | | - linewidths=2, |
102 | | - extent=(-3,3,-2,2)) |
103 | | - |
104 | | -#Thicken the zero contour. |
105 | | -zc = CS.collections[6] |
106 | | -plt.setp(zc, linewidth=4) |
107 | | - |
108 | | -plt.clabel(CS, levels[1::2], # label every second level |
109 | | - inline=1, |
110 | | - fmt='%1.1f', |
111 | | - fontsize=14) |
112 | | - |
113 | | -# make a colorbar for the contour lines |
114 | | -CB = plt.colorbar(CS, shrink=0.8, extend='both') |
115 | | - |
116 | | -plt.title('Lines with colorbar') |
117 | | -#plt.hot() # Now change the colormap for the contour lines and colorbar |
118 | | -plt.flag() |
119 | | - |
120 | | -# We can still add a colorbar for the image, too. |
121 | | -CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) |
122 | | - |
123 | | -# This makes the original colorbar look a bit out of place, |
124 | | -# so let's improve its position. |
125 | | - |
126 | | -l,b,w,h = plt.gca().get_position().bounds |
127 | | -ll,bb,ww,hh = CB.ax.get_position().bounds |
128 | | -CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) |
129 | | - |
130 | | - |
131 | | -#savefig('contour_demo') |
132 | | -plt.show() |
133 | | -#!/usr/bin/env python |
134 | | -""" |
135 | | -Illustrate simple contour plotting, contours on an image with |
136 | | -a colorbar for the contours, and labelled contours. |
137 | | -
|
138 | | -See also contour_image.py. |
139 | | -""" |
140 | | -import matplotlib |
141 | | -import numpy as np |
142 | | -import matplotlib.cm as cm |
143 | | -import matplotlib.mlab as mlab |
144 | | -import matplotlib.pyplot as plt |
145 | | - |
146 | | -matplotlib.rcParams['xtick.direction'] = 'out' |
147 | | -matplotlib.rcParams['ytick.direction'] = 'out' |
148 | | - |
149 | | -delta = 0.025 |
150 | | -x = np.arange(-3.0, 3.0, delta) |
151 | | -y = np.arange(-2.0, 2.0, delta) |
152 | | -X, Y = np.meshgrid(x, y) |
153 | | -Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
154 | | -Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
155 | | -# difference of Gaussians |
156 | | -Z = 10.0 * (Z2 - Z1) |
157 | | - |
158 | | - |
159 | | -# You can use a colormap to specify the colors; the default |
160 | | -# colormap will be used for the contour lines |
161 | | -plt.figure() |
162 | | -im = plt.imshow(Z, interpolation='bilinear', origin='lower', |
163 | | - cmap=cm.gray, extent=(-3,3,-2,2)) |
164 | | -levels = np.arange(-1.2, 1.6, 0.2) |
165 | | -CS = plt.contour(Z, levels, |
166 | | - origin='lower', |
167 | | - linewidths=2, |
168 | | - extent=(-3,3,-2,2)) |
169 | | - |
170 | | -#Thicken the zero contour. |
171 | | -zc = CS.collections[6] |
172 | | -plt.setp(zc, linewidth=4) |
173 | | - |
174 | | -plt.clabel(CS, levels[1::2], # label every second level |
175 | | - inline=1, |
176 | | - fmt='%1.1f', |
177 | | - fontsize=14) |
178 | | - |
179 | | -# make a colorbar for the contour lines |
180 | | -CB = plt.colorbar(CS, shrink=0.8, extend='both') |
181 | | - |
182 | | -plt.title('Lines with colorbar') |
183 | | -#plt.hot() # Now change the colormap for the contour lines and colorbar |
184 | | -plt.flag() |
185 | | - |
186 | | -# We can still add a colorbar for the image, too. |
187 | | -CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) |
188 | | - |
189 | | -# This makes the original colorbar look a bit out of place, |
190 | | -# so let's improve its position. |
191 | | - |
192 | | -l,b,w,h = plt.gca().get_position().bounds |
193 | | -ll,bb,ww,hh = CB.ax.get_position().bounds |
194 | | -CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) |
195 | | - |
196 | | - |
197 | | -#savefig('contour_demo') |
198 | | -plt.show() |
199 | | -#!/usr/bin/env python |
200 | | -""" |
201 | | -Illustrate simple contour plotting, contours on an image with |
202 | | -a colorbar for the contours, and labelled contours. |
203 | | -
|
204 | | -See also contour_image.py. |
205 | | -""" |
206 | | -import matplotlib |
207 | | -import numpy as np |
208 | | -import matplotlib.cm as cm |
209 | | -import matplotlib.mlab as mlab |
210 | | -import matplotlib.pyplot as plt |
211 | | - |
212 | | -matplotlib.rcParams['xtick.direction'] = 'out' |
213 | | -matplotlib.rcParams['ytick.direction'] = 'out' |
214 | | - |
215 | | -delta = 0.025 |
216 | | -x = np.arange(-3.0, 3.0, delta) |
217 | | -y = np.arange(-2.0, 2.0, delta) |
218 | | -X, Y = np.meshgrid(x, y) |
219 | | -Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
220 | | -Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
221 | | -# difference of Gaussians |
222 | | -Z = 10.0 * (Z2 - Z1) |
223 | | - |
224 | | - |
225 | | -# You can use a colormap to specify the colors; the default |
226 | | -# colormap will be used for the contour lines |
227 | | -plt.figure() |
228 | | -im = plt.imshow(Z, interpolation='bilinear', origin='lower', |
229 | | - cmap=cm.gray, extent=(-3,3,-2,2)) |
230 | | -levels = np.arange(-1.2, 1.6, 0.2) |
231 | | -CS = plt.contour(Z, levels, |
232 | | - origin='lower', |
233 | | - linewidths=2, |
234 | | - extent=(-3,3,-2,2)) |
235 | | - |
236 | | -#Thicken the zero contour. |
237 | | -zc = CS.collections[6] |
238 | | -plt.setp(zc, linewidth=4) |
239 | | - |
240 | | -plt.clabel(CS, levels[1::2], # label every second level |
241 | | - inline=1, |
242 | | - fmt='%1.1f', |
243 | | - fontsize=14) |
244 | | - |
245 | | -# make a colorbar for the contour lines |
246 | | -CB = plt.colorbar(CS, shrink=0.8, extend='both') |
247 | | - |
248 | | -plt.title('Lines with colorbar') |
249 | | -#plt.hot() # Now change the colormap for the contour lines and colorbar |
250 | | -plt.flag() |
251 | | - |
252 | | -# We can still add a colorbar for the image, too. |
253 | | -CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) |
254 | | - |
255 | | -# This makes the original colorbar look a bit out of place, |
256 | | -# so let's improve its position. |
257 | | - |
258 | | -l,b,w,h = plt.gca().get_position().bounds |
259 | | -ll,bb,ww,hh = CB.ax.get_position().bounds |
260 | | -CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) |
261 | | - |
262 | | - |
263 | | -#savefig('contour_demo') |
264 | | -plt.show() |
265 | | -#!/usr/bin/env python |
266 | | -""" |
267 | | -Illustrate simple contour plotting, contours on an image with |
268 | | -a colorbar for the contours, and labelled contours. |
269 | | -
|
270 | | -See also contour_image.py. |
271 | | -""" |
272 | | -import matplotlib |
273 | | -import numpy as np |
274 | | -import matplotlib.cm as cm |
275 | | -import matplotlib.mlab as mlab |
276 | | -import matplotlib.pyplot as plt |
277 | | - |
278 | | -matplotlib.rcParams['xtick.direction'] = 'out' |
279 | | -matplotlib.rcParams['ytick.direction'] = 'out' |
280 | | - |
281 | | -delta = 0.025 |
282 | | -x = np.arange(-3.0, 3.0, delta) |
283 | | -y = np.arange(-2.0, 2.0, delta) |
284 | | -X, Y = np.meshgrid(x, y) |
285 | | -Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
286 | | -Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
287 | | -# difference of Gaussians |
288 | | -Z = 10.0 * (Z2 - Z1) |
289 | | - |
290 | | - |
291 | | -# You can use a colormap to specify the colors; the default |
292 | | -# colormap will be used for the contour lines |
293 | | -plt.figure() |
294 | | -im = plt.imshow(Z, interpolation='bilinear', origin='lower', |
295 | | - cmap=cm.gray, extent=(-3,3,-2,2)) |
296 | | -levels = np.arange(-1.2, 1.6, 0.2) |
297 | | -CS = plt.contour(Z, levels, |
298 | | - origin='lower', |
299 | | - linewidths=2, |
300 | | - extent=(-3,3,-2,2)) |
301 | | - |
302 | | -#Thicken the zero contour. |
303 | | -zc = CS.collections[6] |
304 | | -plt.setp(zc, linewidth=4) |
305 | | - |
306 | | -plt.clabel(CS, levels[1::2], # label every second level |
307 | | - inline=1, |
308 | | - fmt='%1.1f', |
309 | | - fontsize=14) |
310 | | - |
311 | | -# make a colorbar for the contour lines |
312 | | -CB = plt.colorbar(CS, shrink=0.8, extend='both') |
313 | | - |
314 | | -plt.title('Lines with colorbar') |
315 | | -#plt.hot() # Now change the colormap for the contour lines and colorbar |
316 | | -plt.flag() |
317 | | - |
318 | | -# We can still add a colorbar for the image, too. |
319 | | -CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) |
320 | | - |
321 | | -# This makes the original colorbar look a bit out of place, |
322 | | -# so let's improve its position. |
323 | | - |
324 | | -l,b,w,h = plt.gca().get_position().bounds |
325 | | -ll,bb,ww,hh = CB.ax.get_position().bounds |
326 | | -CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) |
327 | | - |
328 | | - |
329 | 65 | #savefig('contour_demo') |
330 | 66 | plt.show() |
0 commit comments