6 장 Plot using matplotlib, pandas, seaborn

6.2 기본 플롯

  • 타이틀 / X, Y축 이름

  • colors

    • b: blue; - g: green; - c: cyan; - m: magenta; - y: yellow; - k: black; - w: white
  • Line style -: solid; --: dashed; -.: dash-dot; : dotted

  • Symbol markers

    • .: point; ,: pixcel; o: circle; v: down trangle; ^ up-triangle; s: square
    • *: star; +: +, D: diamond
  • 레전드 표시

  • 그리드 표시

6.4 다양한 plots

  1. plt.plot()
  2. plt.boxplot()
  3. plt.hist()
  4. plt.scatter([x축 데이터], [y축 데이터])
  5. plt.bar([x축 데이터], [y축 데이터])
  6. plt.pie([비율 데이터])

6.4.1 상자그림

## {'whiskers': [<matplotlib.lines.Line2D object at 0x7fbe332c7390>, <matplotlib.lines.Line2D object at 0x7fbe33258690>, <matplotlib.lines.Line2D object at 0x7fbe33266550>, <matplotlib.lines.Line2D object at 0x7fbe33258c10>], 'caps': [<matplotlib.lines.Line2D object at 0x7fbe33258b90>, <matplotlib.lines.Line2D object at 0x7fbe332c7550>, <matplotlib.lines.Line2D object at 0x7fbe33266f10>, <matplotlib.lines.Line2D object at 0x7fbe3325e5d0>], 'boxes': [<matplotlib.lines.Line2D object at 0x7fbe332d1410>, <matplotlib.lines.Line2D object at 0x7fbe3325eb90>], 'medians': [<matplotlib.lines.Line2D object at 0x7fbe3325e610>, <matplotlib.lines.Line2D object at 0x7fbe3326e950>], 'fliers': [<matplotlib.lines.Line2D object at 0x7fbe3325eb10>, <matplotlib.lines.Line2D object at 0x7fbe3326ee50>], 'means': []}
## ([<matplotlib.axis.XTick object at 0x7fbe332a8bd0>, <matplotlib.axis.XTick object at 0x7fbe332a8290>], <a list of 2 Text xticklabel objects>)

6.4.2 히스토그램

## ([array([ 0.,  0.,  0.,  1., 21., 37., 36., 35., 13.,  7.]), array([19., 75., 44., 11.,  1.,  0.,  0.,  0.,  0.,  0.])], array([2.  , 2.59, 3.18, 3.77, 4.36, 4.95, 5.54, 6.13, 6.72, 7.31, 7.9 ]), <a list of 2 Lists of Patches objects>)

6.4.4 막대그래프

## ([<matplotlib.axis.XTick object at 0x7fbe330e2e50>, <matplotlib.axis.XTick object at 0x7fbe33181c90>, <matplotlib.axis.XTick object at 0x7fbe33181610>, <matplotlib.axis.XTick object at 0x7fbe3310fe90>, <matplotlib.axis.XTick object at 0x7fbe33099590>], <a list of 5 Text xticklabel objects>)

6.5 seaborn 패키지 & load datasets

  • seaborn패키지의 load_dataset()함수: seaborn패키지의 내장데이터를 가져옴
  • iris data의 데이터타입 확인
## <class 'pandas.core.frame.DataFrame'>
  • iris data의 데이터 컬럼속성 및 데이터 확인
## Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',
##        'species'],
##       dtype='object')
##    sepal_length  sepal_width  petal_length  petal_width species
## 0           5.1          3.5           1.4          0.2  setosa
## 1           4.9          3.0           1.4          0.2  setosa
## 2           4.7          3.2           1.3          0.2  setosa
## 3           4.6          3.1           1.5          0.2  setosa
## 4           5.0          3.6           1.4          0.2  setosa
  • 팁 데이터 가져오기
##    total_bill   tip     sex smoker  day    time  size
## 0       16.99  1.01  Female     No  Sun  Dinner     2
## 1       10.34  1.66    Male     No  Sun  Dinner     3
## 2       21.01  3.50    Male     No  Sun  Dinner     3
## 3       23.68  3.31    Male     No  Sun  Dinner     2
## 4       24.59  3.61  Female     No  Sun  Dinner     4
  • 타이타닉호 데이터
##    survived  pclass     sex   age  ...  deck  embark_town  alive  alone
## 0         0       3    male  22.0  ...   NaN  Southampton     no  False
## 1         1       1  female  38.0  ...     C    Cherbourg    yes  False
## 2         1       3  female  26.0  ...   NaN  Southampton    yes   True
## 3         1       1  female  35.0  ...     C  Southampton    yes  False
## 4         0       3    male  35.0  ...   NaN  Southampton     no   True
## 
## [5 rows x 15 columns]