Trực quan hóa dữ liệu giúp hiểu nhanh mà không cần tính toán phức tạp.
Pygal: package Python mã nguồn mở tạo biểu đồ tương tác, SVG (Scalable Vector Graphics) - vector co giãn không mất chất lượng, nhúng web/dự án.
Pygal hỗ trợ: bar chart, histogram, line plot, gauge...
Gauge chart kết hợp pie chart và doughnut chart, hiển thị giá trị tại một điểm cụ thể.
Cài đặt: pip install Pygal
Ví dụ
import pygal
from pygal.style import Style
custom_style = Style(colors=('#E80080', '#404040', '#9BC850', '#E81190'))
gauge_chart = pygal.Gauge(height=400, width=300, style=custom_style, human_readable=True)
gauge_chart.title = "Gauge plot"
gauge_chart.add("label 1", [0.4])
gauge_chart.add("label 2", [1.2])
gauge_chart.add("label 3", [1.5])
gauge_chart.add("label 3", [1.8])
gauge_chart.render_in_browser()
Đầu ra

Giải thích
- Import pygal và Style.
- Tạo
pygal.Gaugevới height, width, style, human_readable=True. - Đặt title, thêm dữ liệu từng nhãn (mỗi nhãn 1 giá trị).
render_in_browser()hiển thị gauge chart trên trình duyệt.