LoginSignup
4
3

More than 5 years have passed since last update.

Seabornのheatmapで東京の月別平均値を並べてみた。

Last updated at Posted at 2018-12-29

seabornでヒートマップ

seabornていろいろできるんですね。
覚えたてのヒートマップで遊んでみました。
ヒートなので気温を描いてみました。
普通の棒グラフの方がわかりやすいという指摘はさておいて...

こちらのデータを利用させていただきました。
気象庁

今回使用したLibraryです。


import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

元のデータはこのような状態です。


ダウンロードした時刻20189 16:04:44,,,,
,,,,
,,東京,東京,東京
年月,,平均気温(),平均気温(),平均気温()
,,,品質情報,均質番号
Year,Month,Temp,,
2000,1,7.6,8,1
2000,2,6,8,1
2000,3,9.4,8,1
2000,4,14.5,8,1

2017

まずいらない行と列意外のデータをpandasでデータベース化します。

tokyo_temp = pd.read_csv("tokyo_temp2000-2017.csv",usecols=range(0, 3), header=5)

そしてyx軸に対応させるようにピボット化させます。

df_temps_pivot = pd.pivot_table(data=tokyo_temp, values='Temp', columns='Year', index='Month', aggfunc=np.mean)
#aggfunc=np.meanは無くても可能,xy座標が重なってしまったデータの処理のため

プロットします。

plt.figure(figsize=(12, 9))
sns.heatmap(df_ftemps_pivot, annot=True, fmt='g')
plt.title('tokyo_temp2000-2017')
plt.savefig("heatmap.png")
plt.show()

heatmap.png

8月が暑いということがわかりますね。
よく考えたら日本は四季があるということは1年を通しての気温の分散値が大きいという意味ですね。住む場合の暮らしやすさの指標の一つとなりそうです。

今回は欠損データがなかったのできれいにプロットできましたが、欠損がある場合はどうしたらいいのかや、その信頼性はどうやって定義できるのかが勉強したいところです。

4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3