title: Plot 4D data heatmap in Python
body: <p>hey how can I plot a 2D heatmap in 3D? Now I create a python script to make a 2D Heatmap Plot with data from CSV (CSV format: x,y,z,v).
  For example:</p>
  <p>First csv</p>
  <pre><code>0,000;-110,000;110,000;0,101
  </code></pre>
  <p>Second csv</p>
  <pre><code>0,000;-66,000;110,000;0,104
  </code></pre>
  <p>Third csv</p>
  <pre><code>0,000;-22,000;110,000;0,119
  </code></pre>
  <p>....</p>
  <p>In this example, it is a heatmap in xz-plane and I create e.g. five more plots, so that I can insert six xz-plane Plots in a 3D room.
  In <a href="https://stackoverflow.com/questions/54072839/plot-4d-data-as-layered-heatmaps-in-python">4D heatmap plot with matplotlib</a> there is a very nice example for doing it. But I don't know how to use it in my case.</p>
  <pre><code>import numpy as np
  import os
  import matplotlib.pyplot as plt
  from scipy.interpolate import griddata
  
  
  'Create a list for every parameter'
  x = []
  y = []
  z = []
  v = []
  
  file_path = &quot;path/.&quot;
  
  'Insert data from csv into lists'
  for root, dirs, files in os.walk(file_path, topdown=False):
     for name in files:
         if name[-4:] != '.csv': continue
         with open(os.path.join(root, name)) as data:
            data = np.genfromtxt((line.replace(',', '.') for line in data), delimiter=&quot;;&quot;)
            if data[1] == 22: 
              x.append(data[0])
              y.append(data[1])
              z.append(data[2])
              v.append(data[3])
  
  'Create axis data'
  xi = np.linspace(min(x), max(x), 1000)
  zi = np.linspace(min(z), max(z), 1000)
  vi = griddata((x, z), v, (xi[None,:], zi[:,None]), method='cubic')
  
  'Create the contour plot'
  CS = plt.contourf(xi, zi, vi, 20, cmap=plt.cm.rainbow)
  plt.title(&quot;Heatmap xz-plane&quot;, y=1.05, 
            fontweight=&quot;bold&quot;)
  plt.xlabel(&quot;length x in cm&quot;)
  plt.xticks(np.arange(0, 201, step=40))
  plt.ylabel(&quot;height z in cm&quot;)
  plt.yticks(np.arange(110, 251, step=20))
  cbar = plt.colorbar()
  cbar.set_label(&quot;velocity v in m/s&quot;, labelpad=10)
  plt.savefig('testplot.png', dpi=400)  
  plt.show()
  </code></pre>
  <hr>
  <p><sub><em>Satisfying the request of @keepAlive wishing to see the result of his untested answer... :</em></sub></p>
  <p>it actually works great :-)</p>
  <p><a href="https://i.stack.imgur.com/Di7Hp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Di7Hp.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/aPvB5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aPvB5.jpg" alt="enter image description here" /></a></p>