I have a seaborn heatmap with more than 100 labels on Y-axis. I want to change the font color of the Y-labels to red and blue in alternate way. If I have 10 Y-labels, then 5 labels should have the blue font & 5 labels should have the red font in an alternate fashion.
Kindly Help
CodePudding user response:
you can achieve this using ax.ticklabel.font()
. You can even use font to easily differentiate the neighbors. A sample code is given here.
import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set_theme()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
for i, tick_label in enumerate(ax.axes.get_yticklabels()):
if i%2:
tick_label.set_color("blue")
tick_label.set_fontsize("15")
else:
tick_label.set_color("red")
tick_label.set_fontsize("10")