title: Plot 4D plot in python
body: <p>I know that I am beating a dead horse, but I could not find a proper answer.</p>
  
  <p>I want to make a plot from large data:</p>
  
  <pre><code>X-Coord   Y-Coord   Z-Coord   Value
  20'000 rows
  </code></pre>
  
  <p>when I invoke </p>
  
  <pre><code>X, Y = np.meshgrid(X, Y)
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>  Traceback (most recent call last):
    File "new 1.py", line 17, in &lt;module&gt;
      X, Y = np.meshgrid(X, Y)  # &lt;-- returns a 2D grid from initial 1D arrays
    File "C:\Program Files (x86)\lib\site-packages\numpy\lib\function_base.py", line 4698, in meshgrid
      output = [x.copy() for x in output]
    File "C:\Program Files (x86)\lib\site-packages\numpy\lib\function_base.py", line 4698, in &lt;listcomp&gt;
      output = [x.copy() for x in output]
  MemoryError
  </code></pre>
  
  <p>Actually I simply want to have a 3D surface from X Y Z coordinates and to plot value from column Value in this coordinate. Give me please a suggestion</p>
  
  <p>UPD:
  example of data</p>
  
  <pre><code>          X                       Y                       Z                     Value
  -3.6296815834229800E+13 9.0179395964544800E+13  4.3243022996875400E+13  2.3293827867020395e-03
  -3.6546185417114900E+13 8.9339697982272400E+13  4.3845054348437700E+13  2.2153085734286245e-03
  -3.6546185417114900E+13 9.2024057357272400E+13  4.3845054348437700E+13  2.6335681277863542e-03
  -3.6795554999999900E+13 8.8500000000000000E+13  4.4447085699999900E+13  2.2448110225069475e-03
  -3.6795554999999900E+13 9.1184359374999900E+13  4.4447085699999900E+13  2.3661800082893664e-03
  -3.6795554999999900E+13 9.3868718749999900E+13  4.4447085699999900E+13  3.1766708204588683e-03
  -3.6296815834229800E+13 9.0179395964544800E+13  4.3243022996875400E+13  2.3293827867020395e-03
  -3.6546185417114900E+13 9.2024057357272400E+13  4.3845054348437700E+13  2.6335681277863542e-03
  -3.6337452147547400E+13 9.0857342861310100E+13  4.3341127722985300E+13  2.4227047423936087e-03
  -3.6795554999999900E+13 9.3868718749999900E+13  4.4447085699999900E+13  3.1766708204588683e-03
  -3.6586821730432500E+13 9.2702004254037600E+13  4.3943159074547600E+13  2.8272105071883709e-03
  -3.6378088460865000E+13 9.1535289758075300E+13  4.3439232449095200E+13  2.5588155147357474e-03
  -3.6378088460865000E+13 9.1535289758075300E+13  4.3439232449095200E+13  2.6341575316456271e-03
  -3.6586821730432500E+13 9.2702004254037600E+13  4.3943159074547600E+13  2.8628186103490019e-03
  -3.6491956423152800E+13 9.3434980585604900E+13  4.3714133992590100E+13  3.2129310022084552e-03
  -3.6795554999999900E+13 9.3868718749999900E+13  4.4447085699999900E+13  3.1710978217960057e-03
  -3.6700689692720300E+13 9.4601695081567300E+13  4.4218060618042400E+13  3.5478526100425675e-03
  -3.6605824385440600E+13 9.5334671413134600E+13  4.3989035536084900E+13  3.9315260648101454e-03
  -3.6196152400000000E+13 8.8500000000000000E+13  4.3000000000000000E+13  5.1978166985800038e-03
  -3.6495853699999900E+13 8.8500000000000000E+13  4.3723542849999900E+13  4.8689291409766524e-03
  </code></pre>
  
  <p>UPD2:
  Thanks for good solution from @ImportanceOfBeingErnest</p>
  
  <p>finally to speed up data processing during rotation of scatter I reduced the arrays and used another backend. Also added a colorbar for results.</p>
  
  <pre><code>import numpy as np
  from mpl_toolkits.mplot3d import Axes3D
  import matplotlib.pyplot as plt
  from matplotlib import cm
  
  import matplotlib
  matplotlib.use('svg')
  
  x,y,z,v = np.loadtxt("datafile.txt", skiprows=2, unpack=True)
  if len(x) &gt; 400000:
    x = x[::50] 
    y = y[::50] 
    z = z[::50]
    v = v[::50] 
  elif len(x) &gt; 200000:
    x = x[::20] 
    y = y[::20] 
    z = z[::20]
    v = v[::20] 
  elif len(x) &gt; 100000:
    x = x[::10] 
    y = y[::10] 
    z = z[::10]
    v = v[::10]   
  
  fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  
  
  ax.scatter(x,y,z,c=v, s=10, cmap=cm.rainbow)
  
  m = cm.ScalarMappable(cmap=cm.rainbow)
  
  m.set_array(v)
  cbar = plt.colorbar(m)
  
  plt.show()
  </code></pre>