Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การสร้าง Funnel Chart ด้วย Pygal ใน Python


บทนำ

Visualization ช่วยเข้าใจข้อมูล Pygal: แพ็กเกจ Python โค้ดเปิด สร้างกราฟโต้ตอบ SVG ปรับแต่งได้ ดาวน์โหลดคุณภาพสูง ฝังในเว็บได้

Funnel Chart

แสดงการลดหรือเพิ่มขึ้นแบบขั้นตอน (progressive reduction/expansion) ใช้กับข้อมูลขาย หุ้น ฯลฯ

การติดตั้ง

pip install Pygal

ตัวอย่าง: สร้าง Funnel Chart

import pygal
from pygal.style import Style

custom_style = Style(colors=('#E80080', '#404040', '#9BC850', '#E81190'))

funnel_chart = pygal.Funnel(height=400, width=300, style=custom_style)
funnel_chart.title = "Funnel Plot"
funnel_chart.add("Label 1", [0.4])
funnel_chart.add("Label 2", [1.2])
funnel_chart.add("Label 3", [1.5])
funnel_chart.add("Label 3", [1.8])
funnel_chart.render_in_browser()

ผลลัพธ์

การสร้าง Funnel Chart ด้วย Pygal ใน Python

คำอธิบาย

  • นำเข้า pygal และ Style
  • สร้าง Funnel กำหนด height, width, style
  • กำหนดสี custom style
  • ตั้งค่า title และเพิ่มข้อมูลแต่ละ label
  • เรียก render_in_browser() แสดงผล