matplotlib 2D plot from x,y,z values
Question: I am a Python beginner.

I have a list of X values

    
    
    x_list = [-1,2,10,3]
    

and I have a list of Y values

    
    
    y_list = [3,-3,4,7]
    

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

    
    
    X   Y    Z
    -1  3    5
    2   -3   1
    10  4    2.5
    3   7    4.5
    

and the Z values are stored in `z_list = [5,1,2.5,4.5]`. 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:

    
    
    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()
    

How to get this done correctly?


Answer: Here is one way of doing it:

    
    
    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()
    

[![enter image description
here](http://i.stack.imgur.com/WIIRd.png)](http://i.stack.imgur.com/WIIRd.png)

I followed this link: [How to plot a density map in
python?](http://stackoverflow.com/questions/24119920/how-to-plot-a-density-
map-in-python)

