- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2021-12-06T15:47:31+09:00;2021-12-06T12:51:54+09:00","default:inoue.ko","inoue.ko")
*Seaborn
https://seaborn.pydata.org/
~
seaborn は、Python の可視化ライブラリである [[Matplotlib]] のラッパー関数として動作するライブラリーで、より簡潔なコードで美麗なグラフを作成することができます。
~
***Seaborn のインストールとインポート
Python 言語のライブラリとしてのインストールになるので、一般の Python3 の環境であれば、Terminalから以下のコマンドでインストールできます。
$ pip3 install seaborn
import する際は、以下のように記述するのが一般的です。
import matplotlib.pyplot as plt
import seaborn as sns
sns.set( ) # seabornの機能を有効化
Google Colaboratory では Jupyter Notebook で利用できるライブラリーが「すべてインストール済み」という前提なので、ローカル環境での作業のように、必要なライブラリのインストールを行う必要はなく、コードセルに import 文を書くだけで使うことができます。
~
~
**メソッド
***ヒストグラム sns.displot
# seaborn のヒストグラム表示機能を用いた詳細設定
sns.displot( df['total_bill'], bins=12 , color='#0033AA', height=6 , aspect=2, kde=True )
~
***ボックスプロット sns.boxplot
# seaborn の boxplot を用いた「箱ひげ図」の描画
sns.boxplot( data = df , x = 'day' , y = 'total_bill' , order = ['Thur','Fri','Sat','Sun'] )
~
***散布図 sns.scatterplot
# seaborn の scatterplot を用いた「散布図」の描画
plt.figure( figsize=(12, 8) )
sns.scatterplot( data = df , x = 'total_bill' , y = 'tip' )
~
# カラムの「質的変数」(この例では曜日)の違いを色で区別して描画
plt.figure(figsize=(12, 8))
sns.scatterplot( data = df , x = 'total_bill' , y = 'tip' , hue = 'day' , s = 100 )
~
# カラムの「質的変数」(この例では ランチとディナー)の違いを形で区別して 描画
plt.figure(figsize=(12, 8))
sns.scatterplot( data = df , x = 'total_bill' , y = 'tip' , style = 'time' , s = 100 )
~
# カラムの「量的変数」(この事例では「テーブルサイズ」)をドットの大きさを変えて描画する
plt.figure(figsize=(12, 8))
sns.scatterplot( data = df , x = 'total_bill' , y = 'tip' , hue = 'day' , size = 'size' , sizes = (100,1000) , alpha = 0.5 )
~
***散布図行列 sns.pairplot
# seaborn の pairplot を用いた「散布図行列」の描画
sns.pairplot( data = df , hue = 'day' , height = 4 , aspect = 1 )
~
***ヒートマップ sns.heatmap
# ヒートマップの表示
plt.figure( figsize=(16, 24))
sns.heatmap(df2 , linewidths=.5 , cmap="coolwarm" , fmt="d" , annot=True , robust=True )
~
~
~