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

วิธีหาชื่อ Style ที่มีใน Matplotlib

ใช้ plt.style.library เพื่อดู Style ทั้งหมดที่มีอยู่ใน Matplotlib

ขั้นตอน

  1. Import matplotlib.pyplot
  2. Print plt.style.library

ตัวอย่างโค้ด


import matplotlib.pyplot as plt
print(plt.style.library)

Style ที่นิยมใช้

Styleลักษณะ
seaborn-v0_8ลักษณะ Seaborn (สมัยใหม่)
ggplotลักษณะ R ggplot2
bmhBayesian Methods for Hackers
fivethirtyeightลักษณะ FiveThirtyEight
dark_backgroundพื้นหลังสีดำ
classicMatplotlib Classic
Solarize_Light2สีสว่าง Solarized

การใช้งาน Style


# ใช้ Style ชั่วคราว
with plt.style.context('seaborn-v0_8'):
    plt.plot([1, 2, 3])
    plt.show()

# ใช้ Style ตลอด Session
plt.style.use('ggplot')

# ใช้หลาย Style พร้อมกัน
plt.style.use(['seaborn-v0_8', 'dark_background'])

ผลลัพธ์

แสดง Dictionary ของ Styles ทั้งหมด พร้อม Parameter แต่ละ Style (Output ยาวมาก จึงไม่แสดงทั้งหมด)