title: How do I create a contour plot on magnetometer data?
body: <p>I have been struggling to solve this problem for days.
  I am working on a project <em>Indoor localization based on sensors</em>.
  I am using a dataset that contains magnetometer sensor readings (Columns are X, Y, Z, Magnitude) and want to plot a contour where X and Y are coordinates and z axis should represent the mean values of magnitude.</p>
  <p>I have total 9 such datasets and I have to create a contour plot where I have X and Y as coordinates that look like:</p>
  <p>0,0 | 0,1 | 0,2</p>
  <p>1,0 | 1,1 | 1,2</p>
  <p>2,0 | 2,2 | 2,2</p>
  <p>and Z should be mean of Magnitude.</p>
  <p>Here's what i have tried till now:
  Z needs to be a 2D value so it cannot be a single value. So I used all 9 datasets and got 9 means of magnitude. Here's the code:</p>
  <pre><code># Create an array of all the means of readings on Z axis 
  mag_nmean = np.array((mag_mean, mag_mean1, mag_mean2, mag_mean3, mag_mean4, mag_mean5, mag_mean6, mag_mean7, mag_mean8))
  mag_nmean.shape
  </code></pre>
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  
  fig = plt.figure(figsize=(6,5))
  left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
  ax = fig.add_axes([left, bottom, width, height]) 
  
  start, stop = 0, 5
  
  x_vals = [0, 1, 2]
  y_vals = [0, 1, 2]
  X, Y = np.meshgrid(x_vals, y_vals)
  
  Z = mag_nmean.reshape((3,3))
  
  # X, Y and Z should have same shape
  print(X.shape, Y.shape, Z.shape)
  
  cp = plt.contourf(X, Y, Z, cmap = plt.cm.jet)
  #plt.colorbar(cp)
  contours = plt.contour(X, Y, Z, colors = 'black')
  plt.clabel(contours, fontsize = 8)
  
  plt.colorbar(cp)
  plt.axis(aspect = 'image')
  plt.show()
  </code></pre>
  <p>The above code plots:</p>
  <p>This is what I have tried although I do not understand the plot so I dont know if I am on the right path.</p>
  <p>I cannot figure out how to solve this problem.</p>