Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting points in python

Tags:

python

plot

I want to plot some (x,y) points on the same graph and I don't need any special features at all short of support for polar coordinates which would be nice but not necessary. It's mostly for visualizing my data. Is there a simple way to do this? Matplotlib seems like way more than I need right now. Are there any more basic modules available? What do You recommend?

like image 209
Double AA Avatar asked Jul 25 '11 16:07

Double AA


2 Answers

import matplotlib.pyplot as plt 
x = range(1,10) 
y = range(1,10) 
plt.plot(x,y,'o')
plt.show()

Here's a simple line with made up x, y. Note: x and y are lists.

Their lengths should be equal or you'll get a error. Cheers!

like image 180
karlzafiris Avatar answered Oct 07 '22 00:10

karlzafiris


Absolutely. Matplotlib is the way to go.

The pyplot module provides a nice interface to get simple plots up and running fast, especially if you are familiar with MatLab's plotting environment. Here is a simple example using pyplot:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x_points = xrange(0,9)
y_points = xrange(0,9)
p = ax.plot(x_points, y_points, 'b')
ax.set_xlabel('x-points')
ax.set_ylabel('y-points')
ax.set_title('Simple XY point plot')
fig.show()
like image 36
jeremiahbuddha Avatar answered Oct 07 '22 00:10

jeremiahbuddha