Seaborn学习09:热图

import matplotlib.pyplot as plt
import seaborn as sns

data = sns.load_dataset("flights")
print(data.head())
flights = data.pivot("month", "year", "passengers")  # 行索引,列索引,数据
print(flights.head())

f, ax = plt.subplots(figsize=(9, 6))
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax)
plt.show()

运行结果:

   year     month  passengers
0  1949   January         112
1  1949  February         118
2  1949     March         132
3  1949     April         129
4  1949       May         121
year      1949  1950  1951  1952  1953  ...  1956  1957  1958  1959  1960
month                                   ...                              
January    112   115   145   171   196  ...   284   315   340   360   417
February   118   126   150   180   196  ...   277   301   318   342   391
March      132   141   178   193   236  ...   317   356   362   406   419
April      129   135   163   181   235  ...   313   348   348   396   461
May        121   125   172   183   229  ...   318   355   363   420   472

显示效果:

 

转载于:https://www.cnblogs.com/jumpkin1122/p/11519479.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值