gpt4 book ai didi

python - 如何在 python 中绘制没有曲线的单个点?

转载 作者:太空狗 更新时间:2023-10-30 00:49:33 30 4
gpt4 key购买 nike

我想在绘图上绘制带有误差条的单个数据点,但我不想有曲线。我怎样才能做到这一点?是否有一些“不可见”的线型,或者我可以将线型设置为无色(但标记仍然必须可见)?

这是我现在的图表:

plt.errorbar(x5,y5,yerr=error5, fmt='o')
plt.errorbar(x3,y3,yerr=error3, fmt='o')

plt.plot(x3_true,y3_true, 'r--', label=(r'$\lambda = 0.3$'))
plot(x5_true, y5_true, 'b--', label=(r'$\lambda = 0.5$'))

plt.plot(x5,y5, linestyle=':', marker='o', color='red') #this is the 'ideal' curve that I want to add
plt.plot(x3,y3, linestyle=':', marker='o', color='red')

my graph

我想保留两条虚线,但不想要两条虚线。我怎样才能做到这一点?我怎样才能改变标记的颜色,使红色曲线有红色点,蓝色曲线有蓝色点?

最佳答案

你可以使用scatter:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 10)
y = np.sin(x)
plt.scatter(x, y)
plt.show()

enter image description here

或者:

plt.plot(x, y, 's')

enter image description here

编辑:如果你想要错误栏,你可以这样做:

plt.errorbar(x, y, yerr=err, fmt='o')

enter image description here

关于python - 如何在 python 中绘制没有曲线的单个点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27773057/

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