繁体   English   中英

轮廓标签matplotlib的位置,用于自定义标签

[英]location of contour label matplotlib for custom labels

我正在尝试绘制一系列椭圆作为轮廓。 如何在相应的椭圆上指定参数常数C的值。

import matplotlib.pyplot as plt
from numpy import arange, meshgrid

delta = 0.025
xrange = arange(-20.0, 20.0, delta)
yrange = arange(-20.0, 20.0, delta)
X, Y = meshgrid(xrange,yrange)

fig=plt.figure()
ax=fig.add_subplot(111)
ax.set_xlim(xmin=-6, xmax=6)
ax.set_ylim(ymin=-4, ymax=4)

# F is one side of the equation, G is the other
F = (X**2)/2.0+(Y**2)
for C in range(6,14,3):
    CS=plt.contour(X, Y, F - C, [0],label=str(C))

plt.show()

有没有一种方法可以找到轮廓clabel的x,y坐标,然后用自定义值C替换默认值。我不想借助鼠标单击。

要标记轮廓,可以使用clabel 由于在这种情况下,您似乎想直接用轮廓的值标记轮廓,因此无需确定坐标或以任何方式操作标签。

import matplotlib.pyplot as plt
from numpy import arange, meshgrid

delta = 0.025
x_range = arange(-20.0, 20.0, delta)
y_range = arange(-20.0, 20.0, delta)
X, Y = meshgrid(x_range,y_range)

fig=plt.figure()
ax=fig.add_subplot(111)
ax.set_xlim(xmin=-6, xmax=6)
ax.set_ylim(ymin=-4, ymax=4)

# F is one side of the equation, G is the other
F = (X**2)/2.0+(Y**2)

C = range(6,14,3)
CS = plt.contour(X, Y, F, C)
labels = plt.clabel(CS)

xy = [t.get_position() for t in labels]
print(xy)

plt.show()

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM