I am plotting contours, using an example from this link (code and output plot below)
I want the labels for each contour as a legend in the corner, not along the contour lines. Is there a way?
CodePudding user response:
Try this:
delta = 0.15
x = np.arange(1.5, 2.5, delta)
y = np.arange(1.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z = (np.exp(X - Y))
CS1 = plt.contour(X, Y, Z)
nm, lbl = CS1.legend_elements()
lbl_ = [i for i in range(1, len(lbl))]
plt.legend(nm, lbl_)
plt.title('matplotlib.pyplot.contour() Example')
plt.show()
CodePudding user response: