[부스트캠프 AI tech Data Viz] week04 (2022.02.07)

5-1 Polar Coordinate(colab)

  • 극 좌표계를 사용하는 시각화
  • R(거리), Theta(각)을 이용하여 plot
  • 회전, 주기성 등을 표현하기에 적합
  • projection = polar을 추가하여 사용
  • scatter, line, bar 모두 가능

Radar Chart

  • 극 좌표계를 사용하는 대표적인 차트
  • 별 모양으로 생겨 Star plot으로 불리기도 함
  • 중심점을 기준으로 N개의 변수 값을 표현할 수 있음
  • 데이터의 Quality를 표현하기에 좋음(ex.캐릭터의 강함, 비교)
  • 각 feature는 독립적이며 척도가 같아야 함
  • 면적이 중요해 보이지만 feature의 순서에 따라 많이 달라짐
  • feature가 많아질 수록 가독성이 떨어짐

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
plt.show()

  • ax.set_rmax(): 최댓값
  • ax.set_rmin(): 최솟값
  • ax.set_rticks([1, 1.5, 2]): ticks 설정
  • ax.set_rlabel_position(-90): 라벨 위치 조절
  • ax.set_thetamin(45): 부채꼴 최솟값
  • ax.set_thetamax(135): 부채꼴 최대값
  • ax.scatter(theta, r): 산점도
  • ax.bar(theta, r):
  • ax.plot(theta, r):
  • ax.fill(theata, r):
  • 데이터 시각화
stats = ["HP", "Attack", "Defense", "Sp. Atk", "Sp. Def", "Speed"]
values = pokemon.iloc[0][stats].to_list()
theta = np.linspace(0, 2*np.pi, 6, endpoint=False)
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.plot(theta, values)
ax.fill(theta, values, alpha=0.5)

  • 끝점을 연결하기 위해서 마지막에 첫번째 값을 한번 더 추가해주어야 함.

5-2 Pie Charts(colab)

  • 가장 많이 사용하는 차트지만...지양
    • 비교어려움
    • 유용성 떨어짐
    • 오히려 bar plot이 더 유용(각도 << 길이) --> 차라리 함께사용
    • waffle chart가 더 비교에 유용

- Donut chart

  • 디자인적으로 선호
  • 인포그래픽으로 종종 사용

- Sunburst Chart

  • 햇살을 닮은 차트
  • 계층적으로 데이터를 시각화하는 데 사용
  • 구현 난이도에 비해 화려 / 오히려 Treemap을 추천

5-3 다양한 시각화 라이브러리(colab)

  • Missingno

    • 결측치 확인
    • missingno
    • matrix형태로 결측치 표현, 하얀색이 결측치
    • 오른쪽의 숫자는 결측치가 없는 column의 수를 의미
      import missingno as msno
      msno.matrix(titanic, 
                sort='descending', # ascending
               )

    • bar형태로도 표현 가능
      msno.bar(titanic)

  • Treemap

    • 계층적 데이터 시각화
    • squarify / plotly
    • 모자이크 플롯(Mosaic plot)과 유사
      fig, ax = plt.subplots()
      values = [100, 200, 300, 400]
      label = list('ABCD')
      color = ['#4285F4', '#DB4437', '#F4B400', '#0F9D58']
      squarify.plot(values, label=label, color=color, pad=0.2, 
                     text_kwargs={'color':'white', 'weight':'bold'}, ax=ax)
      ax.axis('off')
      plt.show()

  • Waffle Chart

    • 와플 형태로 discrete하게 값을 나타내는 차트
    • pywaffle
    • icon을 사용한 waffle chart도 가능
    • pie chart보다 향상된 시각화
    from pywaffle import Waffle
    fig = plt.figure(
      FigureClass=Waffle, 
      rows=5, 
      values={'A': 50, 'B': 45, 'C': 15}, 
      cmap_name='tab10',
      # colors=["#232066", "#983D3D", "#DCB732"]
      legend={'loc': 'lower left', 'bbox_to_anchor': (0, -0.4), 
      'ncol': 3, 'framealpha': 0}
      #vertical=True # 세로로
      #block_arranging_style= 'new-line' #새로운 라인으로 #default:snake
      )
    • Icon
      fig = plt.figure(
      FigureClass=Waffle, 
      rows=10,     
      values=data, 
      legend={'loc': 'lower left', 'bbox_to_anchor': (0, -0.4), 'ncol': 3, 'framealpha': 10},
      icons='child',
      icon_legend=True,
      font_size=15,
      interval_ratio_x = 1,
      block_arranging_style= 'new-line'
      )
      plt.show()

  • Venn

    • 벤다이어그램
    • 출판 및 프레젠테이션
    • 사용이 어려움
    • matplotlib_venn

좋은 웹페이지 즐겨찾기