Issue
I have two heatmap subplots using Seaborn (shown below) I have looked for tutorials/help etc everywhere but I cannot figure out:
Q) How to change the color of the colorbar numbers on each of the heatmaps?
I want them both to be the color "yellow" and not the default "black"
Thank you for you time.
line_df
total_df
fig.set_facecolor("Blue")
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
sns.heatmap(line_df, ax = ax1, annot=True, annot_kws={'fontsize': 16, 'fontweight':'bold'}, xticklabels=line_df.columns, yticklabels=line_df.index, cbar_kws={'orientation':'vertical'} )
ax1.yaxis.label.set_color("Blue")
ax1.tick_params(colors="yellow")
sns.heatmap(total_df, ax = ax2, annot=True, annot_kws={'fontsize': 16, 'fontweight':'bold',}, xticklabels=total_df.columns, yticklabels=False, cbar_kws={'orientation':'vertical'})
ax2.get_yaxis().set_visible(False)
ax2.tick_params(colors="yellow")
fig.tight_layout()
plt.show()
plt.close()
Solution
You will need to use this to change the parameters including font color by calling each of the axis colorbar and then change the tick_params for that axis. As there was no data available, I have used random arrays to demonstrate the same. You can find more information tick_params here and on collections here
df1 = np.random.rand(5, 5)
df2 = np.random.rand(5, 5)
import seaborn as sns
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
sns.heatmap(data = df2, ax = ax1, annot=True, annot_kws={'fontsize': 16, 'fontweight':'bold'},
cbar_kws={'orientation':'vertical'} )
sns.heatmap(data = df1, ax = ax2, annot=True, annot_kws={'fontsize': 16, 'fontweight':'bold',},
cbar_kws={'orientation':'vertical'})
cbar1 = ax1.collections[0].colorbar
cbar1.ax.tick_params(labelsize=20, colors='yellow')
cbar2 = ax2.collections[0].colorbar
cbar2.ax.tick_params(labelsize=20, colors='yellow')
plt.show()
Answered By - Redox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.