gpt4 book ai didi

python - 每个数据点具有不同文本的散点图

转载 作者:行者123 更新时间:2023-12-01 17:46:38 25 4
gpt4 key购买 nike

我正在尝试制作散点图并使用列表中的不同数字来注释数据点。例如,我想绘制 yx 的图,并用 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()

import matplotlib.pyplot as plt
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 website:

enter image description here

关于python - 每个数据点具有不同文本的散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com