matplotlib 2D plot from x,y,z values
<p>I am a Python beginner.</p>

<p>I have a list of X values </p>

<pre><code>x_list = [-1,2,10,3]
</code></pre>

<p>and I have a list of Y values</p>

<pre><code>y_list = [3,-3,4,7]
</code></pre>

<p>I then have a Z value for each couple. Schematically, this works like that:</p>

<pre><code>X   Y    Z
-1  3    5
2   -3   1
10  4    2.5
3   7    4.5
</code></pre>

<p>and the Z values are stored in <code>z_list = [5,1,2.5,4.5]</code>.
I need to get a 2D plot with the X values on the X axis, the Y values on the Y axis, and for each couple the Z value, represented by an intensity map.
This is what I have tried, unsuccessfully:</p>

<pre><code>X, Y = np.meshgrid(x_list, y_list) 
fig, ax = plt.subplots()
extent = [x_list.min(), x_list.max(), y_list.min(), y_list.max()]
im=plt.imshow(z_list, extent=extent, aspect = 'auto')
plt.colorbar(im)
plt.show()
</code></pre>

<p>How to get this done correctly?</p>

<p>Here is one way of doing it:</p>

<pre><code>import matplotlib.pyplot as plt
import nupmy as np
from matplotlib.colors import LogNorm

x_list = np.array([-1,2,10,3])
y_list = np.array([3,-3,4,7])
z_list = np.array([5,1,2.5,4.5])

N = int(len(z_list)**.5)
z = z_list.reshape(N, N)
plt.imshow(z, extent=(np.amin(x_list), np.amax(x_list), np.amin(y_list), np.amax(y_list)), norm=LogNorm(), aspect = 'auto')
plt.colorbar()
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/WIIRd.png" rel="nofollow"><img src="http://i.stack.imgur.com/WIIRd.png" alt="enter image description here"></a></p>

<p>I followed this link: <a href="http://stackoverflow.com/questions/24119920/how-to-plot-a-density-map-in-python">How to plot a density map in python?</a></p>

python matplotlib imshow