Matplotlib散点图在每个数据点具有不同的文本 [英] Matplotlib scatter plot with different text at each data point

查看:90
本文介绍了Matplotlib散点图在每个数据点具有不同的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制散点图,并用列表中的不同数字注释数据点. 因此,例如,我想绘制yx并用n中的相应数字进行注释.

I am trying to make a scatter plot and annotate data points with different numbers from a list. So, for example, I want to plot y vs x and annotate with corresponding numbers from n.

y = [2.56422, 3.77284, 3.52623, 3.51468, 3.02199]
z = [0.15, 0.3, 0.45, 0.6, 0.75]
n = [58, 651, 393, 203, 123]
ax = fig.add_subplot(111)
ax1.scatter(z, y, fmt='o')

有什么想法吗?

推荐答案

我不知道任何采用数组或列表的绘图方法,但是可以在迭代n中的值时使用annotate(). >

I'm not aware of any plotting method which takes arrays or lists but you could use annotate() while iterating over the values in n.

y = [2.56422, 3.77284, 3.52623, 3.51468, 3.02199]
z = [0.15, 0.3, 0.45, 0.6, 0.75]
n = [58, 651, 393, 203, 123]

fig, ax = plt.subplots()
ax.scatter(z, y)

for i, txt in enumerate(n):
    ax.annotate(txt, (z[i], y[i]))

annotate()的格式设置选项很多,请参见 matplotlib网站:

There are a lot of formatting options for annotate(), see the matplotlib website:

这篇关于Matplotlib散点图在每个数据点具有不同的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆