如何在图中将轮廓标签作为传奇
我正在绘制轮廓,使用此链接中的示例(下面的代码和输出图) https://www.geeksforgeeks.org/matplotlib-pyplot-contour-in-in-python/
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib
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)
fmt = {}
strs = ['1', '2', '3', '4', '5', '6', '7']
for l, s in zip(CS1.levels, strs):
fmt[l] = s
plt.clabel(CS1, CS1.levels, inline = True,
fmt = fmt, fontsize = 10)
plt.title('matplotlib.pyplot.contour() Example')
plt.show()
我希望每个轮廓的标签作为角落的传奇,而不是沿轮廓线。有办法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下:
Try this:
为轮廓创建自定义图例。
label.remove()
以下是最终代码的样子:
<
a a href =“ https://i.sstatic.net/hfzkkkw 。
to create a custom legend for your contours.
label.remove()
Below is what the final code looks like:
And the output gives: