[英]Add an additional axes to seaborn heatmap
我有一個保留矩陣作為海底熱圖。 我想知道如何在哪里以及如何添加附加軸。 我想在熱圖旁邊附加一個垂直條形圖,以顯示給定同類群組中的新用戶數量。 任何幫助或指針將不勝感激。
我嘗試使用fig.add_axes,但是對於要使用的參數和值有些迷失。 干杯
parameter = 'Total Rent'
recordtpye = 'Tenant'
dataset = df[(df['Account Record Type'] == recordtpye)]
grouped = dataset.groupby(['TenanatCohort','BookingPeriod'])
cohorts = grouped.agg({'Request ID': pd.Series.nunique,'Total Rent':np.sum})
cohorts.rename(columns={'Request ID': 'Number of Bookings'}, inplace=True)
cohorts.reset_index(inplace=True)
cohorts.set_index(['TenanatCohort', 'BookingPeriod'], inplace=True)
cohort_group_size = dataset.groupby('TenanatCohort').agg({'Tenant: Account Name': pd.Series.nunique})
user_retention_numbers = cohorts[parameter].unstack(0)
bookings_per_cohort = \
cohorts.reset_index()\
.groupby('TenanatCohort')\
.agg({parameter: np.sum})[parameter]\
.divide(cohort_group_size['Tenant: Account Name'])
inp = user_retention_numbers
sns.set(style='white')
fig = plt.figure(figsize=(16,7))
graph = sns.heatmap(inp.T,
mask=inp.T.isnull(),
cmap="Blues",
annot=True,
fmt=".0f",
annot_kws={"size":10});
graph.set_xlabel("Booking Period")
graph.set_ylabel("Cohort Group")
plt.yticks(rotation=0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.