Hi,
I'm trying to customize the colorbar in a seaborn clustermap, this is my code:
lut2={ 'up-regulated':'mediumturquoise', 'down-regulated':'darkorange'}
ax = sns.clustermap(data_matrix ,yticklabels=False, vmin=-6, vmax=6.3,
figsize=(9, 16),row_colors=annotations_df,cmap='coolwarm',
cbar_kws={"label": "log2-fold change" ,
"ticks":[-6,-5,-4,-3,-2,-1,0, 1, 2,3,4,5,6] })
enter ax.fig.subplots_adjust(right=0.7)
ax.ax_cbar.set_position((0.8, .4, .03, .4))
ax.ax_heatmap.set_xticklabels(ax.ax_heatmap.get_xmajorticklabels(), fontsize = 16)
ax.ax_row_colors.set_xticklabels(ax.ax_row_colors.get_xmajorticklabels(), fontsize = 14)
plt.tick_params(labelsize=15)
handles = [Patch(facecolor=lut2[name]) for name in lut2)
plt.legend(handles, lut2, title='Genes',facecolor='white',fontsize=14,title_fontsize =16, bbox_to_anchor=(1, 0.85),
bbox_transform=plt.gcf().transFigure, loc='right')
I was able to set the label title with cbar_kws agrument, I changed the position of the colorbar with ax_cbar_set.position and I changed the yticks label with this command plt.tick_params(labelsize=15), but I'm not able to change the size of the label? Is there a parameter to pass inside "cbar_kws" in order to change the size of the label or other command to do that?
Thanks in advance,
Elisa
1 answer
Based on here and adapted to your code, I think. Try near the end if yours:
ax.ax_cbar.set_ylabel("log2-fold change",size=25);
Leave off the semi-colon if not the last line or your aren't using Jupyter.
Minimal reproducible example worked out with; adapted from the Seaborn documentation for clustermap here under 'Examples' since none provided in OP):
import seaborn as sns
iris = sns.load_dataset("iris")
species = iris.pop("species")
ax = sns.clustermap(iris,cbar_kws={"label": "log2-fold change" ,
"ticks":[-6,-5,-4,-3,-2,-1,0, 1, 2,3,4,5,6] })
ax.ax_cbar.set_ylabel("log2-fold change",size=25);
Log in to answer this question.
The fragments of code included has syntax errors.