小编Kar*_*a W的帖子

在 Seaborn 热图中的颜色栏上方移动标题

我在 Seaborn 中制作了一个热图,并且我有一个相应的水平颜色条。我已经为颜色栏添加了一个标题,但是,当我真正想要它在颜色栏上方时,标题会出现在颜色栏下方。有什么我可以改变的原因吗?是否可以更改标题的字体大小和颜色栏上标签的大小?

fig, ax = plt.subplots(figsize=(30,12))
graph = sns.heatmap(df_pivot, cmap="Blues", linecolor="white", linewidths=0.1, 
            cbar_kws={"orientation": "horizontal", "shrink":0.40, "aspect":40, "label": "Number of accidents"})


ax.set_title("Number of traffic accidents per day & hour combination", 
fontsize=30, fontweight="bold")

from matplotlib import rcParams
rcParams['axes.titlepad'] = 70 # Space between the title and graph

locs, labels = plt.yticks() # Rotating row labels
plt.setp(labels, rotation=0) # Rotating row labels

ax.xaxis.tick_top() # x axis on top
ax.xaxis.set_label_position('top')

graph.tick_params(axis='both',labelsize=15) # Tick label size
graph
Run Code Online (Sandbox Code Playgroud)

这是目前为止的样子。我希望“事故数量”标题位于颜色条上方,但位于热图下方。我希望颜色条与热图一样宽。

在此处输入图片说明

python matplotlib heatmap colorbar seaborn

7
推荐指数
1
解决办法
4972
查看次数

标签 统计

colorbar ×1

heatmap ×1

matplotlib ×1

python ×1

seaborn ×1