title: Why I am getting different plots for the same data file in python?
body: <p><a href="https://i.stack.imgur.com/UVje7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UVje7.png" alt="Fig1" /></a></p>
  <p><a href="https://i.stack.imgur.com/0UFJo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0UFJo.png" alt="Fig2" /></a></p>
  <p>txt file</p>
  <pre><code>1 1 1
  1 2 2
  2 4 9
  4 5 2
  6 1 1
  6 2 8
  6 4 9
  6 5 2
  2 5 3
  4 2 5
  4 3 8
  4 4 5 
  1 3 4
  1 5 2
  2 1 1
  2 3 4
  </code></pre>
  <p>I got Fig 1 using the following code</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt                                                                                                                                  
  data = np.genfromtxt('file1.txt', delimiter=' ')                                                                                                                                                             
  lats =  data[:,0]                                                                                                                                                                      
  lons =  data[:,1]                                                                                                                                                                     values = data[:,2]                                                                                                                                                                      
  lat_uniq, lat_idx = np.unique(lats, return_inverse=True)
  lon_uniq, lon_idx = np.unique(lons, return_inverse=True)                                                                                                                           
  xre, yre = np.meshgrid(lon_uniq, lat_uniq)
  zre = np.full(xre.shape, np.nan)                                                                                                                                            
  zre[lat_idx, lon_idx] = values
  print(zre)
                                                                                                                                                                                                                                                                                              
  fig, (ax1) = plt.subplots(1,1, figsize = (10, 5))
  cp1 = ax1.contourf(xre, yre, zre, levels=4)
  plt.colorbar(cp1, ax=ax1)
  ax1.set_title(&quot;data are not interpolated&quot;)                                                                                                                                   plt.show()                                                                                                                                                               
  
  </code></pre>
  <p>and I got fig2 by using the below code and same data file</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  data = np.genfromtxt('test.txt', delimiter=' ')
  lats = data[:, 0]
  lons = data[:, 1]
  values = data[:, 2]
  lat_uniq, lat_idx = np.unique(lats, return_inverse=True)
  lon_uniq, lon_idx = np.unique(lons, return_inverse=True)
  xre, yre = np.meshgrid(lon_uniq, lat_uniq)
  # zre = np.full(xre.shape, np.nan)
  zre = np.full(xre.shape, 0)
  zre[lat_idx, lon_idx] = values
  print(zre)
  
  fig, (ax1) = plt.subplots(1, 1, figsize=(10, 5))
  cp1 = ax1.contourf(xre, yre, zre, levels=4)
  plt.colorbar(cp1, ax=ax1)
  ax1.set_title(&quot;data are not interpolated&quot;)
  
  plt.show()
  </code></pre>
  <p>Which of the code and contour plot is correct? The first, second and third column in txt file represents x, y and z values, and I want to create a contour plot using above data file. Thanks.</p>