轮廓、内联标签[重复]

问题描述 投票:0回答:1

我希望标记类似于本指南的轮廓线:https://matplotlib.org/stable/gallery/images_contours_and_fields/contour_demo.html

但是,当我尝试复制它时,命令

clabel
失败并出现以下错误
TypeError: 'QuadContourSet' object is not iterable

这是我的代码。我希望为 2D 函数绘制多个级别,并按其值标记每条线。在我上面链接的指南中找到了类似的风格。

### plot lines of constant lamba_D, and N_D ###

# first, make a grid to calcuate the lambda_Dvalues everywhere 
ne = np.logspace(6,25,1000,base=10) ## makes array of numbers spaced evenly in log
kT = np.logspace(-2,5,1000,base=10) 
kTGrid, neGrid = np.meshgrid(kT,ne)

lambda_D = np.sqrt( eps*kTGrid*eTJ / (neGrid * e**2) ) ## Eq(1.4) Boyd & Sanderson

lambda_Dlevels = [1e-6,1e-4,1e-2,1e0,1e2,1e4]

c2 = ax.contour(kTGrid,neGrid,lambda_D, levels=lambda_Dlevels, colors='black')
c2.clabel(c2,inline=True)
python matplotlib contour
1个回答
2
投票

您没有分享足够的代码,我可以自己运行它,但我相信问题是因为您做了

c2.clabel(c2, inline=True)
而不是
ax.clabel(c2, inline=True)

© www.soinside.com 2019 - 2024. All rights reserved.