How to plot individual points without curve in pyt

2020-03-01 19:48发布

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?

1条回答
Animai°情兽
2楼-- · 2020-03-01 20:36

You can use 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

查看更多
登录 后发表回答