Sage imports from csv and builds numbers greater than 10

Okey, the problem is simple:

I am trying to make a simple scatter plot:

import csv a = csv.reader(open(DATA+'testi1.csv')) G = Graphics() for col in a: time = col[0] conversion = col[2] x_series = time y_series = conversion plot = scatter_plot (zip(x_series,y_series)) G += plot G.set_axes_range(0, 20, 0, 20) G 

From this data:

 1,2,3 2,4,6 3,6,9 4,8,12 5,10,15 6,12,18 

This leads to a graph that works fine until we reach 12 15 18
It looks like this:

 1,3 2,6 3,9 4,1 5,1 6,1 

I tried the same thing by entering values ​​directly into:

 G = Graphics() x_series = (1,2,3,4,5,6) y_series = (3,6,9,12,15,18) plot = scatter_plot(zip(x_series,y_series)) G += plot G.set_axes_range(0, 20, 0, 20) G 

The result is a graph that works great, it comes out without a problem. I assume the problem is with csv.reader, but I have no idea what to do.

+4
source share
1 answer

OK, you can try the following:

 import csv a = csv.reader(open(DATA+'testi1.csv')) G = Graphics() # create 2 lists so as to save the desired column fields x_series=[] y_series=[] # iterate the csv file for x,y,z in a: # append the first and third columns to # x_series and y_series list respectively x_series.append( int(x) ) y_series.append( int(z) ) # then make the scatter plot plot = scatter_plot(zip(x_series,y_series)) G += plot G.set_axes_range(0, 20, 0, 20) G 
+1
source

All Articles