为了账号安全,请及时绑定邮箱和手机立即绑定

Seaborn 热图未将数据正确放置在轴上

Seaborn 热图未将数据正确放置在轴上

慕桂英4014372 2022-09-27 14:55:28
我是使用Seaborn的新手,通常只使用马特洛利布。随着最近的COVID发展,一位主管要求我汇总学生人数的变化以及我们需要为受影响的学生费用提供资金的费用的估计(我在大学预算办公室工作)。我已经能够将我的场景分析放在一起,但现在正试图在热图中可视化这些结果。我希望能够做的是拥有: x-axis be my population change rates, y_axis be my expense change rates, cmap be my new student fees depending on the x & y axis.我的代码当前正在执行的操作是: x-axis is displaying the new student fee category (not sure how to describe this - see picture) y-axis is displaying the population change and expense change (population, expenses) cmap is displaying accurately从本质上讲,我的代码是将每个场景堆叠在y轴上的其他场景之上。这是当前正在生产的图片,这是不正确的:示例输出 - 不正确我用我的代码附加了一个指向Colab Jupyter笔记本的链接,下面是给我带来问题的部分的片段。# Create Pandas DF of Scenario Analysis       df = pd.DataFrame(list(zip(Pop, Exp, NewStud, NewTotal)),                   index = [i for i in range(0,len(NewStud))],                   columns=['Population_Change', 'Expense_Change', 'New_Student_Activity_Fee', 'New_Total_Fee'])# Group this scenario analysis df = df.groupby(['Population_Change', 'Expense_Change'], sort=False).max()# Create Figure fig = plt.figure(figsize=(15,8))ax = plt.subplot(111)# Drop New Student Activity Fee Column. Analyze Only New Total Feedf = df.drop(['New_Student_Activity_Fee'], axis=1)########################### Not Working As Desiredsb.heatmap(df)########################### 
查看完整描述

1 回答

?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

您的数据帧的形状不正确。例如,作为操作的结果,您有 一个 MultiIndex,它仅用于绘图函数的标记。seaborn.heatmap()groupbyPopulation_ChangeExpense_Change

因此,首先删除多余的列,而不是 ,然后执行以下操作:groupby

df = df.pivot(index='Expense_Change', columns='Population_Change', values='New_Total_Fee')

然后应该按预期工作。seaborn.heatmap(df)


查看完整回答
反对 回复 2022-09-27
  • 1 回答
  • 0 关注
  • 100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号