Problems with contour () in python

2

Hello, I'm having some problems with the contour () function of pylab. In the final image, the x and y axis values are ranging from 0 to 600, which was the amount of intervals in my arange (). However, I wanted the values of x and y (-3 to 3) to be

from numpy import exp,arange
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
q=3
def z_func(x,y):
 return exp(-((x**2)+((y/q)**2))/2)

x = arange(-3.0,3.0, 0.01)
y = arange(-3.0,3.0, 0.01)
X,Y = meshgrid(x, y)
Z = z_func(X, Y) 
im = imshow(Z)
cset = contour(Z,linewidths=2)
clabel(cset,inline=True,fmt='%1.1f',fontsize=10)
colorbar(im)
title('$z = e^{-(x^2+(y/q)^2)/2}$')
show()  

I tried to put contour (X, Y, Z), but the situation only got worse ... It's probably a little detail, sorry if the question is too silly, but I've tried everything.

    
asked by anonymous 31.08.2015 / 03:33

1 answer

0

You can define the range of your vector using the extent argument in imshow and contour

from numpy import exp,arange
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
q=3
def z_func(x,y):
 return exp(-((x**2)+((y/q)**2))/2)

x = arange(-3.0,3.0, 0.01)
y = arange(-3.0,3.0, 0.01)
X,Y = meshgrid(x, y)
Z = z_func(X, Y) 
im = imshow(Z, extent=[x.min(), x.max(), y.min(), y.max()])
cset = contour(Z,linewidths=2, extent=[x.min(), x.max(), y.min(), y.max()])
clabel(cset,inline=True,fmt='%1.1f',fontsize=10)
colorbar(im)
title('$z = e^{-(x^2+(y/q)^2)/2}$')
show() 

    
10.12.2015 / 19:47