statistics - python matplotlib - contour plot - confidence intervals -
i'm trying plot contours (doable) on grid of data using matplotlib.pyplot.contour, contours placed @ 1, 2 , 3 sigma away peak value. there neat way apart brute force? thanks!
python version is
python 2.7.2 |epd 7.2-2 (64-bit)| (default, sep 7 2011, 16:31:15) [gcc 4.0.1 (apple inc. build 5493)] on darwin
you can specify list of z-values
contours drawn. have collect correct z-values
distribution. here example '1, 2, , 3 sigma away peak value':
code:
import numpy np import matplotlib.cm cm import matplotlib.mlab mlab import matplotlib.pyplot plt #set 2d gaussian: delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-3.0, 3.0, delta) x, y = np.meshgrid(x, y) sigma = 1.0 z = mlab.bivariate_normal(x, y, sigma, sigma, 0.0, 0.0) #get z values contours 1, 2, , 3 sigma away peak: z1 = mlab.bivariate_normal(0, 1 * sigma, sigma, sigma, 0.0, 0.0) z2 = mlab.bivariate_normal(0, 2 * sigma, sigma, sigma, 0.0, 0.0) z3 = mlab.bivariate_normal(0, 3 * sigma, sigma, sigma, 0.0, 0.0) plt.figure() #plot gaussian: im = plt.imshow(z, interpolation='bilinear', origin='lower', extent=(-50,50,-50,50),cmap=cm.gray) #plot contours @ whatever z values want: cs = plt.contour(z, [z1, z2, z3], origin='lower', extent=(-50,50,-50,50),colors='red') plt.savefig('fig.png') plt.show()
Comments
Post a Comment