I recently stumbled upon a similar question about how to generate a heatmap of frequencies in Python using the MatPlotLib module.
This post was very useful and I could get the individual scripts to run and create heatmaps for the random test data that was inherently generated by the code. However, I am having trouble adapting the code to create a heatmap for the data I am working with. The data is in comma-delineated format (.csv).
I currently have 3788 pairs of average quality ratings saved in this .csv file. These average quality ratings both have a range from 0 - 5. I am trying to create a heatmap that bins the data by .5 increments on both the x and y axis (0-.499, .5-.999, 1-1.499 etc).
I would like to import the first column of the .csv file (webqualityratings) to be the x-values of the heatmap and the second column of the .csv file (inpersonqualityratings) to be the y-values of the heatmap.
The code I was attempting to adapt posted by "ptomato" and edited by Mike Graham is as follows:
import numpy as np
import numpy.random
import matplotlib.pyplot as plt
# Generate some test data
x = np.random.randn(8873)
y = np.random.randn(8873)
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.clf()
plt.imshow(heatmap, extent=extent)
plt.show()
If anyone could aid me in adapting this code to read in the data from my .csv file as specified, I would be eternally grateful!