python 等高线图中缺失水平

Missing levels in python contour plot

我正在尝试绘制具有指定水平的模拟速度场的等高线,我的值在 [75,150] 范围内,我指定我的水平为 levels=[75,95,115,135,150],但它只给我95,115,135 行。我检查了我的 2d 数组,我确实有值 75 和 150 的点位于直线上,但绘图只是没有显示它们。我想知道为什么会这样。非常感谢!! 这是我的代码:

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()

然后我得到了这个:

您缺少 75 和 150 等高线,因为这些值在数组中从未交叉。值 150 存在,值 75(.000000000000014) 存在,但这些是最小值和最大值。轮廓描述了一个 line/surface 边界 .

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