Seaborn热图:自定义标签

时间:2015-12-22 19:17:49

标签: python python-3.x seaborn

根据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')

如何将类似的逻辑应用于y轴刻度标签? 例如,如果我想强化“二月”,将其设为13磅字体,并将其涂成红色,该怎么办?

提前致谢!

1 个答案:

答案 0 :(得分:3)

几乎完全相同的想法,你只需要遍历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")