散点图移动标签
Scatter plot move labels
我制作了一些大港口的地图。使用 'x' 和 'y' 纬度和经度以及 'text' 端口名称。
x,y = map(lonA, latA)
map.scatter(x, y, s=Size, c=color, marker='o', label = 'Ports',alpha=0.65, zorder=2)
for i in range (0,n):
plt.annotate(text[i],xy=(x[i],y[i]),ha='right')
我绘制的点(更大的端口代表更大的点)与标签重叠。我如何将它们绘制得更远一点以提高可读性?
可以使用xytext
参数调整文字位置:
plt.annotate(text[i],xy=(x[i],y[i]),xytext=(x[i]+10,y[i]+10), ha='right')
这里我给你的 xy 位置加了 10。
有关更多信息,您可以在此处查看建议:
https://matplotlib.org/users/annotations_intro.html
@KiralySandor 你是对的,但你需要将文本坐标更改为数据。
for i in range (0,n):
plt.annotate(text[i],xy=(x[i],y[i]),textcoords='data',xytext=(x[i]-9000,y[i]),ha='right')
现在名字更靠左了。
我制作了一些大港口的地图。使用 'x' 和 'y' 纬度和经度以及 'text' 端口名称。
x,y = map(lonA, latA)
map.scatter(x, y, s=Size, c=color, marker='o', label = 'Ports',alpha=0.65, zorder=2)
for i in range (0,n):
plt.annotate(text[i],xy=(x[i],y[i]),ha='right')
我绘制的点(更大的端口代表更大的点)与标签重叠。我如何将它们绘制得更远一点以提高可读性?
可以使用xytext
参数调整文字位置:
plt.annotate(text[i],xy=(x[i],y[i]),xytext=(x[i]+10,y[i]+10), ha='right')
这里我给你的 xy 位置加了 10。 有关更多信息,您可以在此处查看建议: https://matplotlib.org/users/annotations_intro.html
@KiralySandor 你是对的,但你需要将文本坐标更改为数据。
for i in range (0,n):
plt.annotate(text[i],xy=(x[i],y[i]),textcoords='data',xytext=(x[i]-9000,y[i]),ha='right')
现在名字更靠左了。