Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14011

how to get different size heatmaps with same row height's and width's

$
0
0

I'm generating several heatmaps currently using seaborn.heatmap function.

The issue I'm having is that all the dataframes on which these heatmaps are being generated from have different row sizes, but they all have 10 columns. Essentially the shape of my dataframes which are being displayed in the form of a heatmap have variable amount of rows but a constant number of columns columns.

I'm trying to create heatmaps but the plots all look different sizes, even if I do figsize=(10, len(df.index)/2.5), df.index here is the number of rows I have.

Is there a way to generate these heatmaps so that they all have the same width, same cell height, but just an increase or decrease in the overall height of plot if there are more rows or less rows. I want to be able to save all these plots separately.

Code I'm currently using which is not giving me the desired output:

def plot_heatmap(df):    plt.figure(figsize=(10, len(df.index)/2.5))    ax = sns.heatmap(        df,        vmin=0,        vmax=1,        cmap='coolwarm',        annot=True,        fmt='.3f',        linewidths=.5,        cbar=False,        yticklabels=True,        annot_kws={'alpha': 0.25},    )    # Remove axis labels, but keep tick labels    ax.set_ylabel('')    ax.set_xlabel('')    ax.set_title('Some Title')    plt.savefig('Some Title',        dpi=300,        bbox_inches='tight'    )    plt.tight_layout()    plt.show()# Iterate through each virus group and plot the heatmapfor df in group_dfs:    plot_virus_heatmap(df)

Viewing all articles
Browse latest Browse all 14011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>