2

I have a csv file which contains more than 200 000 lines of meteo data. When I want to model the data with matplotlib, this error appears:

Traceback (most recent call last):
  File "try4.py", line 19, in <module>
    X,Y = meshgrid( data_x,data_y )   
  File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 3378, in  meshgrid
    mult_fact = np.ones(shape, dtype=int)   
  File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 148, in ones
    a = empty(shape, dtype, order) 
  ValueError: array is too big.

I found out that a file with 5000 lines max can be processed. How can I bypass the error in order to process all the file of 200000 lines? Here is my code :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from pylab import *


# read CSV as a numpy array
data = mlab.csv2rec('datasets/mix.csv')

# print CSV file headers
print data.dtype.names

# load columns as vectors
data_x = data['longitude']
data_y = data['latitude']
data_u = data['x']
data_v = data['y']

X,Y = meshgrid( data_x,data_y )
U = cos(data_u)
V = sin(data_v)


# plot raw data
Q = quiver( X, Y, U, V, units='width')
qk = quiverkey(Q, 0.5, 0.92, 2, '.', labelpos='W',
               fontproperties={'weight': 'bold'})
title('Current Surface')

plt.show()
brice
  • 24,329
  • 7
  • 79
  • 95
So4ne
  • 1,124
  • 17
  • 38
  • What does an array element look like? This answer: http://stackoverflow.com/questions/13652650/matplotlib-plot-array-size-limit seems to think that there isn't an obvious array limit (and if so at least at 1m+ elements) – ydaetskcoR Jun 26 '13 at 08:14
  • @ydaetskcoR Here is an example //headers X, Y, Latitude, Longitude, VOGRD_201304100000 //data 292, 1, 0.000000, -50.530000, 0 ...and 200 000 other lines like that – So4ne Jun 26 '13 at 08:41
  • 2
    Can you give more information? Which `matplotlib` calls are you using, etc. – tiago Jun 26 '13 at 08:47
  • @tiago I import numpy, pyplot, mlab and pyplat. I want to plot current surface's data so I'm catching x, y, latitude and longitude and I manipulate it with quiver's function. – So4ne Jun 26 '13 at 08:54
  • Please show us some code. We're not sure what you're doing that causes this. – brice Jun 26 '13 at 09:04
  • @brice my post has been edited – So4ne Jun 26 '13 at 09:11
  • Can you also show us the _full_ error you get? – tacaswell Jun 26 '13 at 09:24
  • The error is coming up from `numpy`, not `matplotlib`. Are you using 32bit or 64bit windows? – tacaswell Jun 26 '13 at 09:36
  • @tcaswell I'm using 32bit windows – So4ne Jun 26 '13 at 09:39
  • I think you maybe running into the limits of 32bit addressing. – tacaswell Jun 26 '13 at 09:43

1 Answers1

2

why are you using meshgrid (doc)? It well generate a 200k by 200k array which will not match the dimensions of your u and v data. I think you want to do this

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from pylab import *


# read CSV as a numpy array
data = mlab.csv2rec('datasets/mix.csv')

# print CSV file headers
print data.dtype.names

# load columns as vectors
data_x = data['longitude']
data_y = data['latitude']
data_u = data['x']
data_v = data['y']

U = cos(data_u)
V = sin(data_v)


# plot raw data
Q = quiver(data_x, data_y, U, V, units='width')
qk = quiverkey(Q, 0.5, 0.92, 2, '.', labelpos='W',
               fontproperties={'weight': 'bold'})
title('Current Surface')
tacaswell
  • 84,579
  • 22
  • 210
  • 199