【问题标题】:Plotting a particular set of contour line at desired point or location在所需的点或位置绘制一组特定的等高线
【发布时间】:2022-01-05 11:57:14
【问题描述】:

我想要一个等高线图,显示对应于一组特定 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()

这不是完整的代码。非常感谢任何形式的帮助或提示。

【问题讨论】:

    标签: python numpy matplotlib seaborn contour


    【解决方案1】:

    您可以为轮廓使用不均匀间隔的层数:

    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的表达改一下。

    【讨论】:

      猜你喜欢
      • 2021-12-24
      • 2012-03-25
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 2018-12-10
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多