How do I plot several sns.clustermap heatmaps in a single figure?
2
0
Entering edit mode
4.0 years ago
roy.granit ▴ 890

Hi All,

Is there a way to plot several clustermaps in a single matplotlib figure.

Edit: I'm specifically using https://scvelo.readthedocs.io/scvelo.pl.heatmap.html to generate the heatmap. This returns an object of type seaborn.matrix.ClusterGrid

Thanks!

python seaborn • 6.0k views
ADD COMMENT
0
Entering edit mode

For now I've exported the plots to png files and loaded them into subplots:

plt.figure(figsize=(30, 15))
    plt.suptitle("title", fontsize=22)

    plt.subplot(133)
    plt.imshow(mpimg.imread('./figures/heatmap_2.png',format="png"))
    plt.title("expression")
    plt.grid(None) 
    plt.axis('off')

    plt.subplot(132)
    plt.imshow(mpimg.imread('./figures/heatmap_1.png'), format="png"))
    plt.grid(None) 
    plt.axis('off')

    plt.subplot(131)
    plt.imshow(mpimg.imread('./figures/3.png',format="png"))
    #plt.grid(None) 
    plt.grid(None) 
    plt.axis('off')

    plt.show()

Not ideal, but works..

ADD REPLY
1
Entering edit mode
4.0 years ago

Define an ax my_ax element before, and when calling sns.clustermap use ax=my_ax as one of the parameters

f, ax = plt.subplots(figsize=(5, 6))
sns.clustermap(x="total_bill", y="tip", data=tips, ax=ax);
ADD COMMENT
0
Entering edit mode

Thanks, I'm actually using a specific type of clustermap (https://scvelo.readthedocs.io/scvelo.pl.heatmap.html) and when I try to add 'ax' to it I get an error: TypeError: heatmap() got multiple values for keyword argument 'ax'

ADD REPLY
0
Entering edit mode

I'm also trying to do this and I get the same TypeError. Any other insights?

ADD REPLY
0
Entering edit mode
7 months ago
Wubin ▴ 50

You can plot very complex heatmaps from data frame using python package PyComplexHeatmap: https://dingwb.github.io/PyComplexHeatmap/build/html/gallery.html

In addition, it allows you to composite multiple heatmap into one figure.

enter image description here

enter image description here

enter image description here

enter image description here

ADD COMMENT

Login before adding your answer.

Traffic: 2278 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6