本記事では、下図のようなBox Plotを作図する雛形コードを載せました。
使用したサンプルデータは、機械学習でお馴染みのアイリスデータセットです(下図)。
■本プログラム
#!/usr/bin/env python # coding: utf-8 # In[1]: import pandas as pd df = pd.read_csv('iris-dataset.csv') df # In[2]: import matplotlib.pyplot as plt import matplotlib.ticker as ticker import seaborn as sns plt.rcParams['font.size']=16 sns.set(style='ticks', color_codes=True) sns.set_context('talk') y_list = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'] for my_y in y_list: g = sns.catplot( x = 'species', y = my_y, #hue = 'species', kind = 'box', # 'box' 'point' data = df, ) #g.fig.set_figheight(6) #g.fig.set_fighwidth(30) plt.xlabel('') plt.ylabel(my_y) ax = plt.gca() y_min , y_max = ax.get_ylim() ax.set_ylim(0, y_max) ''' x_ticklabels = ax.get_ticklabels() plt.setp(x_ticklabels, rotatin=70) tick_spaceing = 5 ax.xaxis.set_major_locator(ticker.MultipleLoctor(tick_spacing)) ''' plt.grid() plt.tight_layout() plt.show()
以上
<広告>
リンク