gpt4 book ai didi

python - python 等高线图中缺少级别

转载 作者:行者123 更新时间:2023-11-28 19:11:12 26 4
gpt4 key购买 nike

我正在尝试绘制具有指定水平的模拟速度场的等高线,我的值在 [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()

然后我得到了这个:This is not showing the 75 and 150 contour levels that I specified. Why?

最佳答案

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

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

with modified levels

关于python - python 等高线图中缺少级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39922504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com