Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualize a co-occurrence matrix in pandas/numpy

I have calculated an array with how many % of the total number of permutations contain all different pairs combinations. Now I want to visualise this as for example a heat map. I have the following code for calculation:

#occurrences matrix
a = np.array(np.array_split(np.random.binomial(1,.5,30),10), dtype='f')

#co-occurrences matrix
acov=np.dot(a.T, a)
acov[np.diag_indices_from(acov)]=0
acov /= acov.sum()

And then i try this for visualisation:

plt.imshow(acov,interpolation='nearest')
plt.colorbar()
plt.show()

However I dont really know what im doing, first time I use a heatmap so not sure what im seeing. What I would like is a graph with the same shape as the array where each square has a colour intensity representing how large it is on a scale from 0-1.

like image 881
user3139545 Avatar asked Oct 23 '25 18:10

user3139545


1 Answers

what about this?

plt.imshow(acov,interpolation='nearest', cmap='Reds')
plt.colorbar()
plt.show()

enter image description here

using seaborn.heatmap():

sns.heatmap(acov)

enter image description here

like image 104
MaxU - stop WAR against UA Avatar answered Oct 26 '25 07:10

MaxU - stop WAR against UA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!