RaynDrop - 1 year ago 123

Python Question

I am trying to plot contours with specified levels of a simulated velocity field, my values are in the range of [75,150], and I specified my levels to be

`levels=[75,95,115,135,150]`

Here is my code:

`import numpy as np`

import matplotlib.pyplot as plt

from matplotlib.patches import Ellipse

#some parameters...does not matter

i=60*np.pi/180 #inclination

r=100 #radius

vc=150

vr=0

x=np.arange(-100,100,1)

y=np.arange(-100,100,1)

xx,yy=np.meshgrid(x,y)

#simulate velocity fields....does not matter either

def projv((x, y),v_c, v_r, inc):

projvy = v_c*x*np.cos(inc)/np.sqrt(x**2+y**2) + v_r*y*np.cos(inc)/np.sqrt(x**2+y**2)

projvx = v_c*y/np.sqrt(x**2+y**2) + v_r*x/np.sqrt(x**2+y**2)

v = np.sqrt(projvx**2 + projvy**2)

return v.ravel()

#here is my 2d array

vel = projv((xx,yy),vc, vr, i).reshape(200,200)

#levels I specified

levels=[75,95,115,135,150]

cs=plt.contour(x,y,vel,levels)

plt.clabel(cs,inline=1,fontsize=9)

plt.show()

Then I got this:

Answer Source

You are missing the 75 and 150 contours because those values are never crossed in the array. The value 150 exists, and the value 75(.000000000000014) exist, but those are the min and max values. Contours describe a line/surface **boundary**.

```
#levels modified
levels=[76,95,115,135,149]
cs=plt.contour(x,y,vel,levels)
plt.clabel(cs,inline=1,fontsize=9)
```