gpt4 book ai didi

python - 如何在散点图的顶部绘制附加点?

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:38 25 4
gpt4 key购买 nike

我的 Pandas 数据框为 df,具有两个属性 df.one (=x) 和 df.two (=y)。现在,我想绘制这些数据点的散点图。我用过

ax1 = fig.add_subplot(111)
ax1.scatter(df.one,df.two,c = 'g',marker = 'o',alpha = 0.2)

现在,我想绘制 C 给出的数据点的质心。我应该如何在上面的散点图上叠加质心?我试过了:

ax1.scatter(C[:,0],C[:,1],c = 'r',marker = 'x')

但它覆盖了散点图,我想覆盖它。是否有任何保留选项,类似于 matlab

最佳答案

如果您需要在原始图上叠加点,请使用

ax.plot(x, y)

例如

ax = plt.subplot(1, 1, 1)
ax.scatter([1, 2, 3], [1, 2, 3])
ax.plot(1.5, 1.5, "or")

enter image description here

如果将列表传递给 x 和 y,则可以将多个点添加到绘图中。另外,如果您需要在重点之外添加一些注释,请尝试

ax.annotate("Some explanation", x, y)

关于python - 如何在散点图的顶部绘制附加点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44505762/

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