Problems with Contour() in python

Asked

Viewed 162 times

2

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

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 just got worse... It’s probably some small detail, sorry if the question is too silly, but I’ve tried everything.

1 answer

0


You can define the range of your vector using the argument extent in the 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() 

imagem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.