18-12-11-視覺化庫Seaborn學習筆記(七:Heatmap)
阿新 • • 發佈:2018-12-17
1、資料準備
import matplotlib.pyplot as plt
import numpy as np;
np.random.seed(0)
import seaborn as sns;
sns.set()
uniform_data = np.random.rand(3, 3)
print (uniform_data)
heatmap = sns.heatmap(uniform_data)
ax = sns.heatmap(uniform_data, vmin=0.2, vmax=0.5)
normal_data = np.random.randn(3, 3) print (normal_data) ax = sns.heatmap(normal_data, center=0)
flights = sns.load_dataset("flights")
flights.head()
'''
year month passengers
0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121
'''
flights = flights.pivot("month", "year", "passengers") print (flights) ax = sns.heatmap(flights) ''' year 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 \ month January 112 115 145 171 196 204 242 284 315 340 360 February 118 126 150 180 196 188 233 277 301 318 342 March 132 141 178 193 236 235 267 317 356 362 406 April 129 135 163 181 235 227 269 313 348 348 396 May 121 125 172 183 229 234 270 318 355 363 420 June 135 149 178 218 243 264 315 374 422 435 472 July 148 170 199 230 264 302 364 413 465 491 548 August 148 170 199 242 272 293 347 405 467 505 559 September 136 158 184 209 237 259 312 355 404 404 463 October 119 133 162 191 211 229 274 306 347 359 407 November 104 114 146 172 180 203 237 271 305 310 362 December 118 140 166 194 201 229 278 306 336 337 405 year 1960 month January 417 February 391 March 419 April 461 May 472 June 535 July 622 August 606 September 508 October 461 November 390 December 432 '''
ax = sns.heatmap(flights, annot=True,fmt="d")
ax = sns.heatmap(flights, linewidths=.5)
ax = sns.heatmap(flights, cmap="YlGnBu")
ax = sns.heatmap(flights, cbar=False)