1 Replies - 575 Views - Last Post: 31 October 2011 - 07:17 AM Rate Topic: -----

#1 emery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-October 11

calling CSV file, plotting it and saving a copy as a pdf

Posted 30 October 2011 - 04:02 PM

I get an error when i try to call the last column of the CSV file with fd(-1)... very frustrating, if there are any other (noob) errors that are obvious in my code, let me know before i encounter it with an error.. thanks!

I also need to save the resulting graph as a PDF, when i come to that part at least... if I could be pointed in the right direction for that, i would appreciate it xD

import csv
import sys

def f1(fd, the_list):
    count = 0
    for line in fd:
        line_list = line.split(',')
        result = 0
        for element in line_list:
            result += [(count, result)]
        the_list += [(count, result)]
        count += 1
    return the_list

def draw_plot(x_axis, y_axis, x_ticks, y_ticks):
    plot.plot(x_axis, y_axis, marker='o', markersize=7.0, label='a simple line')
    plot.xlabel('x axis')
    plot.ylabel('y axis')
    plot.title('a simple plot')

def main():
    fd = open('wing-bowl-data.csv')
    reader = csv.reader(fd)
    step = 1
    x_list = range(19)
    y_list = fd(-1)
    xticks_list = range(min(y_list), max(y_list) + 2, step)
    print yticks_list
    draw_plot(x_list, y_list, xticks_list, yticks_list)

Is This A Good Question/Topic? 0
  • +

Replies To: calling CSV file, plotting it and saving a copy as a pdf

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 797
  • Joined: 08-June 10

Re: calling CSV file, plotting it and saving a copy as a pdf

Posted 31 October 2011 - 07:17 AM

Well...fd(-1) shouldn't work, because fd is a file object, not a callable function.

Could you elaborate on what you are trying to do here? It's not obvious from the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1