Home > Net >  Add upper bound to colour bar
Add upper bound to colour bar

Time:12-10

I'm trying to show enrichment pvals in my dataset. I want to create a heatmap like this:

fig, ax = plt.subplots(figsize=(10,10))
ax = sns.heatmap(pd.DataFrame.from_dict(enrichment_per_decile))
ax.set_title("negative log pval (poisson)")

heatmap with inadequate colorbar

However, due to the extreme values in the upper centre of the figure, I lose out on granularity in the other sections, despite the pval being very significant.

I was following this tutorial on how to customise your colorbar, but I can only seem to get the colorbar to replace the figure, and not be added next to it.

fig, ax = plt.subplots(figsize=(10,10))
ax = sns.heatmap(pd.DataFrame.from_dict(enrichment_per_decile))
ax.set_title("negative log pval (poisson)")
fig.colorbar(
    mpl.cm.ScalarMappable(cmap="magma"),
    cax=ax,
    extend="max")

colorbar replaces heatmap :(

How can I add an upper bound to the colorbar, so that all values above 200 are the same colour, leaving more space for the rest of the figure?

CodePudding user response:

Use vmax parameter.

ax = sns.heatmap(pd.DataFrame.from_dict(enrichment_per_decile), vmax = 200)
  • Related