Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot individual points without curve in 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')

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?

like image 532
Physicist Avatar asked Jan 05 '15 03:01

Physicist


People also ask

How do you plot a straight line in Python?

Matplotlib: Graph/Plot a Straight Line The equation y=mx+c y = m x + c represents a straight line graphically, where m is its slope/gradient and c its intercept. In this tutorial, you will learn how to plot y=mx+b y = m x + b in Python with Matplotlib.

How do you plot area under a curve in Python?

To fill the area under the curve, put x and y with ste="pre", using fill_between() method. Plot (x, y1) and (x, y2) lines using plot() method with drawstyle="steps" method. To display the figure, use show() method.


1 Answers

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

like image 165
elyase Avatar answered Sep 29 '22 18:09

elyase