Dance Party2
Dance Party2

Reputation: 7536

Seaborn Heat Map: Customize A Label

Given the heat map below from here:

flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, annot=True, fmt="d")

for text in ax.texts:
    text.set_size(14)
    if text.get_text() == '118':
        text.set_size(18)
        text.set_weight('bold')
        text.set_style('italic')

How can I apply similar logic to the y-axis tick labels? For example, what if I wanted to embolden "February", make it 13 point font, and color it red?

Thanks in advance!

Upvotes: 3

Views: 6739

Answers (1)

mwaskom
mwaskom

Reputation: 49002

Almost exactly the same idea, you just need to loop over the list of yticklabels:

flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, annot=True, fmt="d")

for label in ax.get_yticklabels():
    if label.get_text() == "February":
        label.set_size(13)
        label.set_weight("bold")
        label.set_color("red")

Upvotes: 7

Related Questions