python - Showing "Value Error: array is too big" error while making a contour plot from a big data file. How to fix? -


i trying make contour plot data file having 4 columns , 48000 rows (i.e. 48000 data points) using matplotlib using rbf interpolation function of scipy.interpolate module. 1st , 2nd columns 2 independent variables of contour plot. 3rd , 4th column 2 variables plotted in separate panels. data file can downloaded following link:

https://drive.google.com/file/d/0b2hpaw59cseqbw9pyvbkthdhtlk/view?usp=sharing

the code follows:

import numpy matplotlib import pyplot plt matplotlib import rc, colorbar scipy.interpolate import rbf  def forceaspect(ax,aspect=1):     im = ax.get_images()     extent =  im[0].get_extent()     ax.set_aspect(abs((extent[1]-extent[0])/(extent[3]-extent[2]))/aspect)  # import data: x, y, z1, z2 = numpy.loadtxt("data_contourplot.dat", usecols = (0,1, 2, 3),  unpack = true)  # set regular grid of interpolation points xi = numpy.linspace(min(x), max(x), 100) yi = numpy.linspace(min(y), max(y), 100) xi, yi = numpy.meshgrid(xi,yi)  rbf1 = rbf(x, y, z1, function='linear') rbf2 = rbf(x, y, z2, function='linear') z1i = rbf1(xi, yi) z2i = rbf2(xi, yi)  fig1 = plt.figure(num=none, figsize=(8, 4), dpi=80, facecolor='w', edgecolor='k') ax = plt.subplot(121) cax = ax.imshow(z1i, vmin=z1.min(), vmax=z1.max(), origin='lower',         extent=[x.min(), x.max(), y.min(), y.max()])  #function adjust layout of plot forceaspect(ay,aspect=1)  #plt.tight_layout() fig1.colorbar(cay) plt.show() 

the error arises in line of rbf function calling follows:

traceback (most recent call last): file "plot_contour_ion_vs_delay_e_c.py", line 29, in <module> rbf1 = rbf(x, y, z1, function='linear') file "/usr/lib/python2.7/dist-packages/scipy/interpolate/rbf.py", line 185, in __init__ r = self._call_norm(self.xi, self.xi) file "/usr/lib/python2.7/dist-packages/scipy/interpolate/rbf.py", line 207, in _call_norm return self.norm(x1, x2) file "/usr/lib/python2.7/dist-packages/scipy/interpolate/rbf.py", line 107, in _euclidean_norm return sqrt( ((x1 - x2)**2).sum(axis=0) ) valueerror: array big. 

please me fix problem. rbf function have limitation on size deal with. standard practice of coding in python deal big data files , contour plot or 2d/3d plot in general?

i used r-tree interpolating based of current point region:

import numpy np matplotlib import pyplot plt matplotlib import rc, colorbar scipy.interpolate import rbf rtree import index  def forceaspect(ax,aspect=1):     im = ax.get_images()     extent =  im[0].get_extent()     ax.set_aspect(abs((extent[1]-extent[0])/(extent[3]-extent[2]))/aspect)   def norm(x1, x2):     return ((x1 - x2)**2).sum(axis=0)  # import data: x, y, z1, z2 = np.loadtxt("data_contourplot.dat",     usecols = (0, 1, 2, 3),  unpack = true)  idx = index.index() step_x = 0.1 step_y = 0.15 in range(x.shape[0]):     idx.insert(i, (x[i] - step_x, y[i] - step_y, x[i] + step_x, y[i] + step_y))  # set regular grid of interpolation points xi = np.linspace(min(x), max(x), 100) yi = np.linspace(min(y), max(y), 100) xi, yi = np.meshgrid(xi, yi)  flat_xi = xi.flat flat_yi = yi.flat z1i = np.zeros_like(flat_xi) z2i = np.zeros_like(flat_xi) i, (xif, yif) in enumerate(zip(flat_xi, flat_yi)):     ind = np.array(list(idx.intersection((xif - step_x*2, yif - step_y*2, xif + step_x*2, yif + step_y*2))))     rbf1 = rbf(x[ind], y[ind], z1[ind], function='linear')     rbf2 = rbf(x[ind], y[ind], z2[ind], function='linear')     z1i[i] = rbf1(xif, yif)     z2i[i] = rbf2(xif, yif)     if % 100 == 0:         print(i)  z1i = np.resize(z1i, xi.shape) z2i = np.resize(z2i, xi.shape)  fig1 = plt.figure(num=none, figsize=(8, 4), dpi=80, facecolor='w', edgecolor='k') ax = plt.subplot(121) cax = ax.imshow(z1i, vmin=z1.min(), vmax=z1.max(), origin='lower',         extent=[x.min(), x.max(), y.min(), y.max()])  #function adjust layout of plot forceaspect(ax,aspect=1)  #plt.tight_layout() fig1.colorbar(cax) plt.show() 

Comments