1. 기본 bar 그래프 그리기
import pandas as pd
month = [ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' ]
data = {
"Banana":[52, 83, 82, 53, 99, 94, 83, 74, 87, 70, 63, 74],
"Orange":[99, 71, 77, 57, 87, 50, 59, 58, 63, 76, 51, 88],
"mango":[50, 71, 93, 82, 70, 58, 55, 97, 76, 52, 97, 83],
}
df = pd.DataFrame(data,index=month)
df.plot(kind="bar",figsize=(15,10))
2. 스택그래프를 그리려면, stacked = True 추가
df.plot(kind="bar",stacked=True,figsize=(15,10)) # stacked
3. 그래프 값 표기
import pandas as pd
month = [ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' ]
data = {
"Banana":[52, 83, 82, 53, 99, 94, 83, 74, 87, 70, 63, 30],
"Orange":[99, 71, 77, 57, 87, 50, 59, 58, 63, 76, 51, 88],
"mango":[50, 71, 93, 82, 70, 58, 55, 97, 76, 52, 97, 83],
}
df = pd.DataFrame(data,index=month)
ax = df.plot(kind="bar",stacked=True,figsize=(15,10)) # stacked
for c in ax.containers:
labels = [ x.get_height() for x in c ]
ax.bar_label(c, labels=labels, label_type='center')
'Python > Python For Analytics' 카테고리의 다른 글
[ Python ] pandas plot 을 이용한 다양한 graph 그리기 (0) | 2023.05.24 |
---|---|
[ Python ] csv 파일 읽고, 쓰기 ( pandas / csv 모듈 ) (0) | 2023.05.16 |
[ Python ] matplotlib plot Shading Area (특정구간 강조) (0) | 2023.02.03 |
[Python] wordcloud 만들기 (0) | 2021.01.28 |
[Python] seaborn을 이용한 간단한 heatmap 그리기 (0) | 2020.11.28 |
[Python] pandas와 pymssql을 이용하여 MSSQL 연동 (0) | 2020.10.05 |
[Python] padnas Dataframe 에서 astype을 이용하여 숫자형으로 변환할 수 없을 때 to_numeric을 이용 (0) | 2020.08.02 |
[Python] matplotlib - 그래프에 값 표시 하기 (1) | 2020.08.02 |