본문 바로가기

CodeStates

[Python] 데이터 시각화

데이터를 시각화 하는 방법을 알아보자

 

내가 알고 있는 시각화 방법은 크게 두가지가 있다

01. Seaborn : 편리하게 다룰 수 있다.

 

02. Matplotlib : 자세하게 다룰 수 있다.

 

 

데이터 시각화는 어느 데이터를 어떻게 보이고 싶을지에 대한 가능성이 너무나도 열려있어 설명을 해주기는 어렵다. 그래서 몇가지 유용한 레퍼런스를 위주로 설명하고자한다.

 

먼저 Seaborn에 대해서 알아보겠다.

먼저 깃허브의 mwaskom 에서 제공하는 csv데이터를 이용해 시각화를 해보자.

https://github.com/mwaskom/seaborn-data/blob/master/penguins.csv

 

mwaskom/seaborn-data

Data repository for seaborn examples. Contribute to mwaskom/seaborn-data development by creating an account on GitHub.

github.com

 

 

Seaborn

seaborn.pydata.org/examples/index.html

 

Example gallery — seaborn 0.11.1 documentation

 

seaborn.pydata.org

위의 링크를 참고하여 작성하고자 하는 시각화의 형태를 빠르게 찾아 볼 수 있다.

 

일단 우리는 섬마다 분포하는 펭귄의 지느러미 길이를 성별을 나누어 표시를 해보겠다.

 

성별(x축), 지느러미 길이(y축), 섬마다로 나누어 표시한 데이터이다.

 

import pandas as pd

df = pd.read_csv('https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv')

import seaborn as sns

sns.boxplot(data = df, x='sex',y='flipper_length_mm', hue = 'island')

이때의 x 축은 입력할 x축의 데이터, y는 입력할 y축의 데이터, hue는 구분인자를 뜻한다.

seaborn에 관한 설명은 여기까지가 다이다. 다른 시각화들은 종류가 너무 다양하여 위의 레퍼런스를 참조하여 하는 것이 더 효율적이다.

 

Matplotlib 

 

www.machinelearningplus.com/plots/top-50-matplotlib-visualizations-the-master-plots-python/

 

Top 50 matplotlib Visualizations - The Master Plots (w/ Full Python Code) | ML+

A compilation of the Top 50 matplotlib plots most useful in data analysis and visualization. This list helps you to choose what visualization to show for what type of problem using python's matplotlib and seaborn library.

www.machinelearningplus.com

위는 자주쓰이는 Matplot의 50가지 종류를 소개한 레퍼런스이다.

 

matplotlib.org/stable/gallery/index.html

 

Gallery — Matplotlib 3.3.4 documentation

Gallery This gallery contains examples of the many things you can do with Matplotlib. Click on any image to see the full image and source code. For longer tutorials, see our tutorials page. You can also find external resources and a FAQ in our user guide.

matplotlib.org

위는 자주쓰이는 Matplotlib 시각화 종류를 소개한 레퍼런스이다. 레퍼런스를 참고하면 seaborn뿐만 아니라 Matplot을 함께 어떻게 이용할지 잘 설명이 되어있다.

 

matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

 

matplotlib.pyplot.plot — Matplotlib 3.3.4 documentation

Parameters: x, yarray-like or scalarThe horizontal / vertical coordinates of the data points. x values are optional and default to range(len(y)). Commonly, these parameters are 1D arrays. They can also be scalars, or two-dimensional (in that case, the colu

matplotlib.org

그리고 위는 plot을 사용할때 그 안에 파라미터들이 어떻게 들어갈지에 대해 자세히 설명이 되어있는 레퍼런스이다.

 

 

'CodeStates' 카테고리의 다른 글

[통계] #2  (0) 2021.03.14
[통계] #1  (0) 2021.03.14
[Pandas] DataFrame 다루기  (0) 2021.03.08
[Pandas] DataFrame 생성, 저장 및 로드  (0) 2021.03.08
Git과 GitHub 그리고 Colab  (0) 2021.03.08