python matplotlib imshow with difference lenghts in data-array
Question: Is there a way to plot heat map with different row lengths using matplotlib?

like this:

    
    
    plt.imshow( [ [1,2,3], [1,2], [1,2,3,4,5,6,7], [1,2,3,4]])
    plt.jet()
    plt.colorbar()
    plt.show()
    

[Desired image](http://postimg.org/image/geoa9nrxf/)


Answer: Given the desired image, I think you will want to you `plt.pcolormesh` rather
than `imshow` but I may be wrong. In any case I personally would create a
function to pad the array then use a mask so that `imshow` or `pcolormesh`
will not plot those points. For example

    
    
    import matplotlib.pylab as plt
    import numpy as np
    
    def regularise_array(arr, val=-1):
        """ Takes irregular array and returns regularised masked array
    
        This first pads the irregular awway *arr* with values *val* to make 
        it of rectangular. It then applies a mask so that the padded values
        are not displayed by pcolormesh. For this reason val should not
        be in *arr* as you will loose these points.
        """
    
        lengths = [len(d) for d in data]
        max_length = max(lengths)
        reg_array = np.zeros(shape=(arr.size, max_length))
    
        for i in np.arange(arr.size):
            reg_array[i] = np.append(arr[i], np.zeros(max_length-lengths[i])+val)
    
        reg_array = np.ma.masked_array(reg_array, reg_array == val)
    
        return reg_array
    
    data = np.array([[1,2,3], [1,2], [1,2,3,4,5,6,7], [1,2,3,4]])
    
    reg_data = regularise_array(data, val=-1)
    
    plt.pcolormesh(reg_data)
    plt.jet()
    plt.colorbar()
    plt.show()
    

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

The issue with this is you need to take care thet `val` is not in the array.
You could add a simple check for this or base it on the data you are using.
The for loop could probably be vectorised but I cannot work out how.

