I am asking a question stemming from this original post Heatmap with circles indicating size of population
I am trying to replicate this using my dataframe, however, my circles are non aligning to the plot. Secondary, I want to also create a legend which indicates the value relative to the size of circle.
x= {'ID': {0: 'GO:0002474',
1: 'GO:0052548',
2: 'GO:0002483',
3: 'GO:0043062',
4: 'GO:0060333'},
'TERM': {0: 'antigen processing and presentation of peptide antigen via MHC class I',
1: 'regulation of endopeptidase activity',
2: 'antigen processing and presentation of endogenous peptide antigen',
3: 'extracellular structure organization',
4: 'interferon-gamma-mediated signaling pathway'},
'Count': {0: 11, 1: 17, 2: 5, 3: 15, 4: 6},
'Ratio': {0: 18.64, 1: 14.53, 2: 8.47, 3: 12.82, 4: 10.17},
'pvalue': {0: -15.83, 1: -11.39, 2: -9.67, 3: -9.05, 4: -7.41},
'qvalue': {0: -11.63, 1: -7.49, 2: -6.52, 3: -5.63, 4: -4.55},
'Label': {0: 'NODAL', 1: 'NODAL', 2: 'NODAL', 3: 'SHARED', 4: 'NODAL'}}
A2780_GOBP= pd.DataFrame(x)
Attempted Code:
ylabels = A2780_GOBP["TERM"]
xlabels = ["GFP","SHARED","NODAL"]
x, y = np.meshgrid(np.arange(len(xlabels)), np.arange(len(ylabels)))
s = A2780_GOBP["Count"].values
c = A2780_GOBP["pvalue"].values
fig, ax = plt.subplots()
R = s/s.max()/2
circles = [plt.Circle((j,i), radius=r) for r, j, i in zip(R.flat, x.flat, y.flat)]
col = PatchCollection(circles, array=c.flatten(), cmap=cmap)
ax.add_collection(col)
ax.set(xticks=np.arange(3), yticks=np.arange(10),
xticklabels=xlabels, yticklabels=ylabels)
ax.set_xticks(np.arange(3+1)-0.5, minor=True)
ax.set_yticks(np.arange(10+1)-0.5, minor=True)
ax.grid(which='minor')
fig.colorbar(col)
plt.show()
Any help would be greatly appreciated!