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
显示效果: