본문 바로가기

개발/로또 ( Python )

로또 데이터 분석을 위한 데이터 차트 확인 방법 ( Bar Chart )

1. MatplotLib 설치


## python lib 중 pip를 이용하여 matplotlib 생성
# python -m pip install matplotlib

 

2. MatplotLib  Bar 

def GetData(self):
    # selectDataFrame 
    # 데이터 recodeSet을 dataFrame으로 변경하여 SELECT하는 커스텀한 함수
    
    param = {}
    groupByNum = self.dbInfo.selectDataFrame("selectGroupByNum", param)
    # groupByNum 값 ( [참조 이미지1] 참조 )
    ## groupByNum["lwNum"] 
    ### desc : 로또 번호 ( 1 ~ 45 )
    ### value : [1,2,3,4,5,6,7...45]
    ## groupByNum["cnt"]
    ### desc : 각 로또 번호에 따른 count
    ### value : [18,171,173....]

    fig, ax = plt.subplots()
    
    # ax.bar 의 groupByNum["lwNum"] 값은 X 좌표 값
    # ax.bar 의 groupByNum["cnt"] 값은 Y 좌표 값    
    # ax.bar 의 label(groupByNum["lwNum"])의 값은 X값 그래프에 표시
    bar_container = ax.bar(groupByNum["lwNum"], groupByNum["cnt"], label=groupByNum["lwNum"])

    ax.bar_label(bar_container, fmt='{:,.0f}')
    # plt.show 값 ( [참조 이미지2] 참조 )
    plt.show()

- 참조 이미지

- [이미지 참조1] : DB에서 조회한 groupByNum의 DataFrame 값

- [이미지 참조2] : 값을 가지고 결과값 표시


참고자료

https://matplotlib.org/stable/gallery/index.html

'개발 > 로또 ( Python )' 카테고리의 다른 글

로또 데이터 크롤링  (2) 2023.12.22