如何在python中绘制没有曲线的单个点? [英] How to plot individual points without curve in python?

查看:342
本文介绍了如何在python中绘制没有曲线的单个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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')

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

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?

推荐答案

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

或者:

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

如果您想要错误条,您可以这样做:

If you want error bars you can do:

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

这篇关于如何在python中绘制没有曲线的单个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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