LoginSignup
3
1

More than 3 years have passed since last update.

pandas データを可視化

Last updated at Posted at 2019-08-02

グラフ化したい!!

円グラフを作成したい

必要なライブラリーをimportしよう!!

import matplotlib as mpl
import matplotlib.pyplot as plt

おそらく出来てない、、、。強引に作成してみた。是非時間のある時に学習して綺麗にしたい。

# 特徴量について調査して件数を確認した
df0 = df[df['Species'].isin([0])]
df0c = df0.count()
print(df0c)
df1 = df[df['Species'].isin([1])]
df1c = df1.count()
print(df1c)
df2 = df[df['Species'].isin([2])]
df2c = df2.count()
print(df2c)

# x = ['setosa', 'versicolor', 'virginica'] # ラベルの名前を直接入れる
x = list(iris.target_names) # 問1の内容を真似た
y = np.array([50,  50, 50]) # 50件ずつ存在しているので強引に入れた

# 下記は良くわからないけど、消すと年グラフが表示されなくなるので残す。
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.pie(y, labels=x, autopct="%1.1f%%")

plt.show()

箱ひげ図

こちらを参考にした。これで列を指定して箱ひげ図が書けた。

df.sepal_length.plot.box()

バイオリン図

色々調査したけど、上記のやり方が一番分かりやすかったし、移植しやすかった。

箱ひげ図とバイオリン図の違い

http://yyhhyy.hatenablog.com/entry/2016/08/20/220000
箱ひげ図はデータの存在範囲が分かりやすく、最大値や最小値が分かる。ただ、バラツキが分かりにくい。
バイオリン図はどの値が多いかや少ないかが視覚的に分かりやすいという特徴がある。

3
1
0

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
3
1