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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27773057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:14:49  来源:igfitidea点击:

How to plot individual points without curve in python?

pythonplotcurvelinestyle

提问by Physicist

I want to plot individual data points with error bars on a plot, but I don't want to have the curve. How can I do this? Are there some 'invisible' line style or can I set the line style colourless (but the marker still has to be visible)?

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

So this is the graph I have right now:

所以这是我现在的图表:

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

我的图

I want to keep the two dashed curve but I don't want the two dotted curve. How can I do this? And how can I change the color of the markers so I can have red points for the red curve, blue points for the blue curve?

我想保留两条虚线曲线,但我不想要两条虚线曲线。我怎样才能做到这一点?以及如何更改标记的颜色,以便红色曲线为红色点,蓝色曲线为蓝色点?

采纳答案by elyase

You can use scatter:

您可以使用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

在此处输入图片说明

Alternatively:

或者:

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

enter image description here

在此处输入图片说明

EDIT: If you want error bars you can do:

编辑:如果你想要误差线,你可以这样做:

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

enter image description here

在此处输入图片说明