Issue
Having several issues adjusting the colorbar in seaborn.clustermap
. I'm trying to:
- orient the colorbar horizontally
- change the colorbar border color
- change the colorbar tick length
I've checked the documentation for figure.colorbar
to no avail.
Minimal code:
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
#data
corr = np.corrcoef(np.random.randn(10, 200))
#clustermap
kws = dict(cbar_kws=dict(label='Label', ticks=[0,0.50,1], orientation='horizontal'), figsize=(6, 6))
sns.clustermap(corr, cmap="Blues", xticklabels=False, yticklabels=False, **kws)
plt.show()
Solution
You can grab the subplot with the colorbar via g.ax_cbar
. Then you can change its position, title, spines and tick lengths:
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
corr = np.corrcoef(np.random.randn(10, 200))
kws = dict(cbar_kws=dict(ticks=[0, 0.50, 1], orientation='horizontal'), figsize=(6, 6))
g = sns.clustermap(corr, cmap="Blues", xticklabels=False, yticklabels=False, **kws)
x0, _y0, _w, _h = g.cbar_pos
g.ax_cbar.set_position([x0, 0.9, g.ax_row_dendrogram.get_position().width, 0.02])
g.ax_cbar.set_title('colorbar title')
g.ax_cbar.tick_params(axis='x', length=10)
for spine in g.ax_cbar.spines:
g.ax_cbar.spines[spine].set_color('crimson')
g.ax_cbar.spines[spine].set_linewidth(2)
plt.show()
Answered By - JohanC
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.