在所需点或位置绘制一组特定的等高线
Plotting a particular set of contour line at desired point or location
我想要一个等高线图,显示对应于一组特定 x、y 的等高线水平。我尝试增加等高线的数量,但它没有在所需点附近给出等高线。
我想得到一条等高线假设在 (0.1,0.1)
附近,但我做不到,我尝试增加等高线的数量,但 matplotlib 没有在所需点附近绘制它,我也不知道该点附近的等高线水平。
khmax = np.arange(0,0.5,0.001)
Ncmax = np.arange(0,0.5,0.001)
[X, Y] = np.meshgrid(Ncmax,khmax)
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN,50)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
这不是完整的代码。非常感谢任何形式的帮助或提示。
您可以为等高线使用间隔不均匀的层数:
VgN_min = VgN.min()
VgN_max = VgN.max()
number_of_contours = 21
power = 2
levels = np.linspace(VgN_min**(1/power), VgN_max**(1/power), number_of_contours)**power
然后就可以使用这个参数来绘制等高线了:
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN, levels = levels)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
您可以调整 power
值以根据需要更改等高线级别的偏度:
power = 1
power = 3
完整代码
import numpy as np
from matplotlib import pyplot as plt
khmax = np.arange(0,0.5,0.001)
Ncmax = np.arange(0,0.5,0.001)
[X, Y] = np.meshgrid(Ncmax,khmax)
VgN = X*Y
VgN_min = VgN.min()
VgN_max = VgN.max()
number_of_contours = 21
power = 3
levels = np.linspace(VgN_min**(1/power), VgN_max**(1/power), number_of_contours)**power
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN, levels = levels)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
备注
在你的代码中你没有报告 VgN
的表达式,所以我认为它类似于上面代码中的 VgN = X*Y
,所以上面的图像代表了这个等式。根据你VgN
.
的表达来改
我想要一个等高线图,显示对应于一组特定 x、y 的等高线水平。我尝试增加等高线的数量,但它没有在所需点附近给出等高线。
我想得到一条等高线假设在 (0.1,0.1)
附近,但我做不到,我尝试增加等高线的数量,但 matplotlib 没有在所需点附近绘制它,我也不知道该点附近的等高线水平。
khmax = np.arange(0,0.5,0.001)
Ncmax = np.arange(0,0.5,0.001)
[X, Y] = np.meshgrid(Ncmax,khmax)
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN,50)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
这不是完整的代码。非常感谢任何形式的帮助或提示。
您可以为等高线使用间隔不均匀的层数:
VgN_min = VgN.min()
VgN_max = VgN.max()
number_of_contours = 21
power = 2
levels = np.linspace(VgN_min**(1/power), VgN_max**(1/power), number_of_contours)**power
然后就可以使用这个参数来绘制等高线了:
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN, levels = levels)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
您可以调整 power
值以根据需要更改等高线级别的偏度:
power = 1
power = 3
完整代码
import numpy as np
from matplotlib import pyplot as plt
khmax = np.arange(0,0.5,0.001)
Ncmax = np.arange(0,0.5,0.001)
[X, Y] = np.meshgrid(Ncmax,khmax)
VgN = X*Y
VgN_min = VgN.min()
VgN_max = VgN.max()
number_of_contours = 21
power = 3
levels = np.linspace(VgN_min**(1/power), VgN_max**(1/power), number_of_contours)**power
fig, ax = plt.subplots()
contour = plt.contour(X,Y,VgN, levels = levels)
ax.set_title('magnitude of VgN/c')
ax.set_xlabel('Ncmax')
ax.set_ylabel('khmax')
ax.clabel(contour, inline= True, inline_spacing = -1,fmt = '%1.8f',fontsize=8)
plt.show()
备注
在你的代码中你没有报告 VgN
的表达式,所以我认为它类似于上面代码中的 VgN = X*Y
,所以上面的图像代表了这个等式。根据你VgN
.