Heat Map

Hello,

I'm trying to create a heat map from two lists of corresponding X and Y coordinates.

I've tried both numpy.histogram2d() and pyplot.hexbin().

The histogram I get back doesn't correspond to the points I gave it. It seems as if it's sorting each X and Y list and then eliminating some points, which would definitely not give me the coordinates I want. (Also, I want to be able to switch the origin to the upper-left corner, but I can't figure out how to do this with imshow().)

The hexbin graph does correspond to my original points, but rather than having hexagons of equal size, some are super thin and tiny. (I'd also like to fill in the entire graph with background color (I want the axes to extend beyond the data) - is there a way to do that?)

Here's the code I wrote for the histogram and hexbin. Am I doing something wrong? I've attached three graphs - one is my coordinates as a scatter plot, one my histogram result, and the other the hexbin result.

Thanks!
~Rachel

def plotHistogram( coordsTuple ):
    
    plt.clf() # Clears any previous figure
    
    xList = coordsTuple[0]
    yList = coordsTuple[1]

    heatmap, xedges, yedges = npy.histogram2d(xList, yList)
    axesExtent = [0, xedges[-1], 0, yedges[-1]]
    plt.imshow(heatmap, extent = axesExtent)

    plt.title( "Heat Map of User Clicks" )

    name = raw_input("\nImage name and extension: ")
    plt.savefig(name)

def plotHexbins( coordsTuple ):
    
    plt.clf() # Clears any previous figure
    
    xList = coordsTuple[0]
    yList = coordsTuple[1]

    plt.hexbin(xList, yList)

    plt.title( "Heat Map of User Clicks" )

    name = raw_input("\nImage name and extension: ")
    plt.savefig(name)

Coords.png

Histogram.png

Hexbins.png

Hello,

I'm trying to create a heat map from two lists of corresponding X and Y coordinates.

I've tried both numpy.histogram2d() and pyplot.hexbin().

The histogram I get back doesn't correspond to the points I gave it. It seems as if it's sorting each X and Y list and then eliminating some points, which would definitely not give me the coordinates I want. (Also, I want to be able to switch the origin to the upper-left corner, but I can't figure out how to do this with imshow().)
  

Histogram2d works fine for me, I use it more or less the same way you do, so I can't help there.
You can specify the origin in imshow by saying:

plt.imshow(heatmap, extent=axesExtent, origin='upper')

The hexbin graph does correspond to my original points, but rather than having hexagons of equal size, some are super thin and tiny. (I'd also like to fill in the entire graph with background color (I want the axes to extend beyond the data) - is there a way to do that?)
  

You can specify the bins in histogram2d to cover the whole screen (you can also specify bins in hexbin, which should be similar):

xedges, yedges = linspace(0,1400,(1400/50)+1), linspace(0,600,(600/50)+1)
npy.histogram2d(xList, yList, bins=[xedges,yedges])

···

Rachel-Mikel_ArceJaeger@...3044... wrote:

Here's the code I wrote for the histogram and hexbin. Am I doing something wrong? I've attached three graphs - one is my coordinates as a scatter plot, one my histogram result, and the other the hexbin result.

Thanks!
~Rachel

def plotHistogram( coordsTuple ):
        plt.clf() # Clears any previous figure
        xList = coordsTuple[0]
    yList = coordsTuple[1]

    heatmap, xedges, yedges = npy.histogram2d(xList, yList)
    axesExtent = [0, xedges[-1], 0, yedges[-1]]
    plt.imshow(heatmap, extent = axesExtent)

    plt.title( "Heat Map of User Clicks" )

    name = raw_input("\nImage name and extension: ")
    plt.savefig(name)

def plotHexbins( coordsTuple ):
        plt.clf() # Clears any previous figure
        xList = coordsTuple[0]
    yList = coordsTuple[1]

    plt.hexbin(xList, yList)

    plt.title( "Heat Map of User Clicks" )

    name = raw_input("\nImage name and extension: ")
    plt.savefig(name)