18

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?

Physicist
  • 2,848
  • 8
  • 33
  • 62

1 Answers1

40

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

elyase
  • 39,479
  • 12
  • 112
  • 119
  • 1
    sorry for missing some key points. I want the data points to have error bars, so I use plt.errorbar, but I don't want to have the curve associated with the data points with error bar as I will add another smooth curve myself. – Physicist Jan 05 '15 at 03:57
  • with `plot.errorbar` you can do: `plt.errorbar(x, y, yerr=err, fmt='o')` – elyase Jan 05 '15 at 04:01
  • I just posted the code. What have I done wrong? I still have the dotted curve with the data points. – Physicist Jan 05 '15 at 04:04
  • You are doing, `plt.plot(x3,y3, linestyle=':', marker='o', color='red')`, you don't need this, if you already used `errorbar` – elyase Jan 05 '15 at 04:05