I'm looking to make a two, two range colour scheme heatmap where each range corresponds to a separate triangle in the heatmap square.

I am looking for a relevant guide for this heatmap. Any recommended package/library or guides? Thanks!

enter image description here

  • $\begingroup$ Are you using R or Python, i.e. you need a Dataframe and its what language you are okay with? Secondly, are you fine doing a single colour heat map? For example even I know with ggplot2 this is easy if you're using uniform colour scheme? $\endgroup$
    – M__
    Mar 22, 2022 at 13:19
  • $\begingroup$ I'm okay with both, but I prefer more on Python. It's okay if you want to show me the single colour heat map with ggplot2 (I'm okay with R). $\endgroup$
    – raysteven
    Mar 22, 2022 at 13:20
  • $\begingroup$ If you're not married to this idea and just wish to show correlations and significance at the same time, R's corrplot can do this. It uses *, ** etc. as content to show p-value thresholds, and a color scale to show correlation value. $\endgroup$
    – Ram RS
    Mar 22, 2022 at 17:01

1 Answer 1


This solution doesn't reproduce the plot, but it would do if the numerical ranges between the triangles do not overlap.

import matplotlib.pyplot as plt
import seaborn as sns

xx = plt.get_cmap('rocket').copy()
yy = plt.get_cmap('mako').copy()
axis = sns.heatmap(dataframe, vmin=-1, cmap=xx, cbar_kws={'pad': -0.04})
sns.heatmap(dataframe, vmin=0, vmax=1, cmap=yy, ax=axis)

My colour schemes are not great but they are distinct, you can search for more here: https://seaborn.pydata.org/tutorial/color_palettes.html

The idea is this would address a situation where you compare the r-value OR a p-value against another set of values where are > 1. That's what the vmin and vmax are doing.

This is a ONE np array or dataframe solution. In other words you will need to combine your data sets. The solution you want is a two dataframes in one heatmap square. You can put two triangles side-by-side, i.e. one dataframe per heatmap, but I don't know who to place two separate dataframes in one heatmap.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.