본문 바로가기
코딩 수업/파이썬 (업무자동화)

[업무자동화] 진도율 바 그래프 만드는 코드

by Jade S. 2025. 5. 1.
728x90
반응형
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc
from matplotlib.patches import FancyBboxPatch
import matplotlib as mpl

# 한글 폰트 설정
font_path = "C:/Users/MJ/Desktop/월간리포트만들기/NanumGothic.ttf"
font_name = font_manager.FontProperties(fname=font_path).get_name()
rc('font', family=font_name)
mpl.rcParams['axes.unicode_minus'] = False

def draw_pretty_progress_bar(percent):
    fig, ax = plt.subplots(figsize=(6.5, 1.0))
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.axis('off')

    # 텍스트와 그래프 위치 조정
    text_x = 0.01
    bar_left = 0.25
    bar_bottom = 0.32
    bar_width = 0.7
    bar_height = 0.36
    rounding = bar_height / 4

    # 배경 바 (연회색)
    bg_bar = FancyBboxPatch(
        (bar_left, bar_bottom), bar_width, bar_height,
        boxstyle=f"round,pad=0.0,rounding_size={rounding}",
        linewidth=0,
        facecolor='#d3d3d3'
    )
    ax.add_patch(bg_bar)

    # 진도 바 (핫핑크)
    progress_width = bar_width * (percent / 100)
    if percent > 0:
        fg_bar = FancyBboxPatch(
            (bar_left, bar_bottom), progress_width, bar_height,
            boxstyle=f"round,pad=0.0,rounding_size={rounding}",
            linewidth=0,
            facecolor='#FF69B4'
        )
        ax.add_patch(fg_bar)

    # 텍스트 표시
    ax.text(text_x, 0.5, f"진도율: {percent}%", fontsize=13, weight='bold', va='center')

    plt.tight_layout()
    plt.show()

# 실행
draw_pretty_progress_bar(77)

 

>>

728x90
반응형