我想要一個等高線圖,顯示對應于一組特定 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()
它不是完整的代碼。任何形式的幫助或提示都非常感謝。
uj5u.com熱心網友回復:
您可以為輪廓使用不均勻間隔的級別數:
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。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369823.html
標籤:Python 麻木的 matplotlib 海生 轮廓
