x,y 둘다 value를 넣고 싶을때
질문 'product_raw 데이터가 있고 x축은 cloth y축은 season으로 그래프 만들고 싶으면 어떻게 해?'
1. 막대 그래프
import seaborn as sns
import matplotlib.pyplot as plt
# cloth별 season의 빈도수를 계산
season_counts = product_raw.groupby(['cloth', 'season']).size().reset_index(name='counts')
# 막대 그래프 그리기
sns.barplot(data=season_counts, x='cloth', y='counts', hue='season')
plt.xticks(rotation=45)
plt.show()
2. 히트맵
# cloth와 season 빈도수를 교차 테이블로 변환
heatmap_data = product_raw.pivot_table(index='season', columns='cloth', aggfunc='size', fill_value=0)
# 히트맵 그리기
sns.heatmap(heatmap_data, annot=True, fmt='d', cmap='YlGnBu')
plt.show()
- 'viridis': 기본적인 색상 맵으로, 어두운 보라색에서 밝은 노란색까지 변해.
- 'plasma': 보라색에서 노란색, 빨간색으로 변화하는 색상 맵.
- 'inferno': 어두운 빨간색에서 밝은 노란색까지 변화.
- 'magma': 어두운 보라색에서 밝은 노란색까지의 색상.
- 'cividis': 색맹 친화적인 색상 맵.
- 'coolwarm': 차가운 색상(파랑)에서 따뜻한 색상(빨강)으로 변하는 색상 맵.
- 'hot': 검정색에서 빨간색, 노란색으로 변하는 색상 맵.
- 'Blues': 다양한 파란색 음영을 가진 색상 맵.
- 'RdYlBu': 빨간색, 노란색, 파란색 순서로 변화하는 색상 맵.
- 'YlGn': 노란색에서 초록색으로 변하는 색상 맵.
- 'YlGnBu': 노란색에서 초록색, 파란색으로 변하는 색상 맵.
- 'Greens': 다양한 초록색 음영을 가진 색상 맵.
- 'BuGn': 파란색에서 초록색으로 변하는 색상 맵.
- 'Purples': 다양한 보라색 음영을 가진 색상 맵.
- 'Oranges': 다양한 주황색 음영을 가진 색상 맵.
- 'ocean': 파란색에서 청록색으로 변하는 색상 맵.
- 'terrain': 자연적이고 따뜻한 색상의 색상 맵.
- 'Spectral': 다양한 색상으로 변하는 색상 맵.
- 'twilight': 보라색과 파란색 계열의 색상 맵.
- 'twilight_shifted': 'twilight' 색상 맵의 변화된 버전.
- 'cubehelix': 보라색에서 흰색, 빨간색으로 변하는 색상 맵.
- 'gist_earth': 어두운 녹색에서 밝은 노란색으로 변하는 색상 맵.
- 'gist_stern': 청록색에서 파란색, 초록색으로 변하는 색상 맵.
- 'gnuplot': 녹색, 주황색, 파란색이 포함된 색상 맵.
- 'BrBG': 초록색과 갈색이 결합된 색상 맵.
3. 도트 플롯
sns.scatterplot(data=product_raw, x='cloth', y='season')
plt.xticks(rotation=45)
plt.show()
4. 누적 막대 그래프
import pandas as pd
# cloth별 season 빈도수를 계산
season_counts = product_raw.groupby(['cloth', 'season']).size().unstack(fill_value=0)
# 누적 막대 그래프
season_counts.plot(kind='bar', stacked=True)
plt.xticks(rotation=45)
plt.ylabel('Counts')
plt.show()
5. 분포 그래프
sns.countplot(data=product_raw, x='cloth', hue='season')
plt.xticks(rotation=45)
plt.show()
6. 파이차트(참고 사이트)