今天我在做一个函数内部的热图。这没什么好奇怪的:热图显示了我城市中每个地区的值,函数内部的参数之一是district_name
。在
我希望我的功能打印相同的热图,但它突出显示选定的地区(最好是通过粗体文本)。在
我的代码是这样的:
def print_heatmap(district_name, df2):
df2=df2[df2.t==7]
pivot=pd.pivot_table(df2,values='return',index= 'district',columns= 't',aggfunc ='mean')
sns.heatmap(pivot, annot=True, cmap=sns.cm.rocket_r,fmt='.2%',annot_kws={"size": 10})
所以我需要访问ax的值,所以如果我输入print_heatmap('Macul',df2)
,我可以粗体说“Macul”。我有办法吗?在
我试图使用mathtext
,但由于某些原因,在这种情况下我不能使用粗体:
但这带来了:
ValueError:
f{macul}$
^
Expected end of text (at char 0), (line:1, col:1)
谢谢
我认为在seaborn中很难明确地做到这一点,您可以通过迭代轴(annot)和ticklabels中的文本并将它们的属性设置为“高亮显示”一行。在
下面是这种方法的一个例子。在
相关问题 更多 >
编程相关推荐