【发布时间】:2020-08-10 06:19:24
【问题描述】:
我创建了一个 seaborn 热图来总结 Teils_U 系数。数据在热图中水平显示。现在,我想旋转数据和图例。我知道您可以在绘图中旋转 x 轴和 y 轴标签,但是如何旋转数据和图例?
这是我的代码:
#creates padnas dataframe to hold the values
theilu = pd.DataFrame(index=['Y'],columns=matrix.columns)
#store column names in variable columns
columns = matrix.columns
#iterate through each variable
for j in range(0,len(columns)):
#call teil_u function on "ziped" independant and dependant variable -> respectivley x & y in the functions section
u = theil_u(matrix['Y'].tolist(),matrix[columns[j]].tolist())
#select respecive columns needed for output
theilu.loc[:,columns[j]] = u
#handle nans if any
theilu.fillna(value=np.nan,inplace=True)
#plot correlation between fraud reported (y) and all other variables (x)
plt.figure(figsize=(20,1))
sns.heatmap(theilu,annot=True,fmt='.2f')
plt.show()
这是我正在寻找的图像:
如果您需要样本数据或 teil_u 函数来重现问题,请告诉我。谢谢
【问题讨论】:
标签: python matplotlib plot seaborn heatmap