首页 > 其他 > 详细

Seaborn学习09:热图

时间:2019-09-14 17:21:36      阅读:76      评论:0      收藏:0      [点我收藏+]
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

显示效果:

技术分享图片

 

Seaborn学习09:热图

原文:https://www.cnblogs.com/jumpkin1122/p/11519479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!