Closed GordianArnav closed 2 months ago
Please upload your data and code so I can reproduce and fix this bug @GordianArnav .
I guess there may be something wrong with your code cause such a bug has never been reported.
I can only provide the code, plt.show() produces the plot perfectly, however only when saving issue arrises
col_ha = HeatmapAnnotation(Int=anno_simple(col_df['Int_Type'],cmap='Set1',
add_text=False,legend=True, text_kws={'fontsize':label_size}),
nCells=anno_barplot(col_df['nCells'],colors = 'gray',legend=False, height = 20),
label_side='left',legend_side = 'right',legend_width=40,axis=1,label_kws=
{'fontsize':label_size},ticklabels_kws={'labelsize':label_size})
row_ha = HeatmapAnnotation(
n_genes=anno_simple(row_df['nGenes'], cmap='RdPu',
height=10, add_text=True, text_kws={'rotation':0, 'fontsize':12,'color':'black'},
majority=False, linecolor='black',linewidths=0.005),
mean_pct_total_counts=anno_simple(row_df['mean_pct_total_counts'],cmap='RdPu',
height=10,linecolor='black',linewidths=0.005),
axis=0,legend_hpad=20,legend_width=10,label_side='bottom',wgap=3,label_kws={'fontsize':label_size})
plt.figure(figsize=fig_size)
cm = ClusterMapPlotter(data=cross_tab,
col_cluster=True, col_cluster_metric='correlation',
row_cluster=True,row_cluster_metric='correlation',
left_annotation=row_ha, top_annotation=col_ha,
label=heatmap_metric,row_dendrogram=True,
col_dendrogram=True,show_rownames=True,
show_colnames=True,verbose=0,legend=True,legend_anchor='ax_heatmap',legend_width=50,
cmap='bwr',xticklabels_kws={'labelrotation':-90,'labelsize':label_size},
yticklabels_kws={'labelsize':label_size},annot = cross_tab_annot,
row_names_side='right',row_dendrogram_size=10,linecolor='black',linewidths=0.005,
fmt=f'',annot_kws = {'weight':'bold'})`
cm.ax_heatmap.set_title(f"Method - {method}", fontsize = title_size ,y=1.08)
plt.yticks(weight='bold')`
if save == True:
plt.savefig(f"heatmap.pdf", dpi=600, format='pdf', bbox_inches='tight')
If you ran any example from the documentation website and saved the figure, would you get the same issue?
Nope the examples work fine
Then, there may be something wrong with your data or the code. You have to debug yourself cause I can not see your data. Here are some suggestions: (1). Only the heatmap, without any annotations, save it into pdf, and see whether it works. (2). Add annotations one by one. (3). Remove all optional parameters and add them one by one.
Thanks, even the heatmap without any annotations, the colorbar is not getting saved
Please run:
plt.figure()
cm = ClusterMapPlotter(data=cross_tab,
cmap='bwr',annot = True)
plt.savefig(f"heatmap.pdf", bbox_inches='tight')
and let's see what happens. If the figure is OK, then add parameter one by one.
Okay that works
Update: Added everything back and it is related to yticklabel size
OK. Congrats. You know what to do next.
Is this the issue on your side, or is there any bug with the package?
I mean there is a limit to the yticklabel size you can put depending upon the figure size, I was trying to come up with an algorithm that
1) Automatically finds best figure size based on length of xticks and yticks such that all ticks are displayed -> (100,45) is my dataset 2) Increase label size so that everything is visible and proportionate
So maybe issue on my side, however colors should be saved regardless of yticklabel size right?
Describe the bug Plt.show() displays the correct legends, however when I save the plot, legends are not saved
Screenshots