Link to home
Start Free TrialLog in
Avatar of scogger1974
scogger1974

asked on

Python Matplotlib - Howto make line graph

I have the attached code. I want to take load.csv and plot it to a line graph using matplotlib and python. The code attached isnt't working and I am looking for guidance. Any ideas?
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import matplotlib.cbook as cbook
import matplotlib.ticker as ticker

datafile = open('load.csv')
print 'loading', datafile
r = mlab.csv2rec(datafile)

r.sort()
r = r[-30:]


fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(r.SERVER, r.LOAD, 'o-')
fig.autofmt_xdate()


N = len(r)
ind = np.arange(N)

def format_date(x, pos=None):
    thisind = np.clip(int(x+0.5), 0, N-1)
    return r.date[thisind].strftime('%Y-%m-%d')

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(ind, r.adj_close, 'o-')
ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
fig.autofmt_xdate()

plt.show()

Open in new window

load.csv
ASKER CERTIFIED SOLUTION
Avatar of ilalopoulos
ilalopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial