I am looking to label the contours lines similar to this guide: https://matplotlib.org/stable/gallery/images_contours_and_fields/contour_demo.html
However, when I try to replicate it, the command clabel
fails with the following error TypeError: 'QuadContourSet' object is not iterable
Heres my code. I am looking to plot multiple levels for a 2D function and label each line by its value. In a similar style found in the guide I linked above.
### 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)
You didn't share enough of your code that I can run it myself, but I believe the issue is because you did c2.clabel(c2, inline=True)
instead of ax.clabel(c2, inline=True)
.