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

การสร้าง Dot Plot ด้วย Pygal ใน Python


บทนำ

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

Dot Plot

แผนภูมิสถิติ แสดงข้อมูลเป็นจุด ขนาดจุดแทนค่า ค่ายิ่งใหญ่ จุดยิ่งใหญ่

การติดตั้ง

pip install Pygal

ตัวอย่าง: สร้าง Dot Plot

import pygal
from pygal.style import Style

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

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

ผลลัพธ์

การสร้าง Dot Plot ด้วย Pygal ใน Python

คำอธิบาย

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