Graphing a line and scatter points using Matplotlib?

Posted by Patrick O'Doherty on Stack Overflow See other posts from Stack Overflow or by Patrick O'Doherty
Published on 2010-06-16T16:06:30Z Indexed on 2010/06/16 16:32 UTC
Read the original article Hit count: 349

Filed under:
|

Hi guys

I'm using matplotlib at the moment to try and visualise some data I am working on. I'm trying to plot around 6500 points and the line y = x on the same graph but am having some trouble in doing so. I can only seem to get the points to render and not the line itself. I know matplotlib doesn't plot equations as such rather just a set of points so I'm trying to use and identical set of points for x and y co-ordinates to produce the line.

The following is my code

from matplotlib import pyplot
import numpy
from pymongo import *

class Store(object):
    """docstring for Store"""
    def __init__(self):
        super(Store, self).__init__()
        c = Connection()
        ucd = c.ucd
        self.tweets = ucd.tweets

    def fetch(self):
        x = []
        y = []
        for t in self.tweets.find():
            x.append(t['positive'])
            y.append(t['negative'])
        return [x,y]

if __name__ == '__main__':
    c = Store()
    array = c.fetch()
    t = numpy.arange(0., 0.03, 1)

    pyplot.plot(array[0], array[1], 'ro', t, t, 'b--')
    pyplot.show()

Any suggestions would be appreciated,

Patrick

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib