ใช้ plt.style.library เพื่อดู Style ทั้งหมดที่มีอยู่ใน Matplotlib
ขั้นตอน
- Import matplotlib.pyplot
- Print
plt.style.library
ตัวอย่างโค้ด
import matplotlib.pyplot as plt
print(plt.style.library)
Style ที่นิยมใช้
| Style | ลักษณะ |
|---|---|
seaborn-v0_8 | ลักษณะ Seaborn (สมัยใหม่) |
ggplot | ลักษณะ R ggplot2 |
bmh | Bayesian Methods for Hackers |
fivethirtyeight | ลักษณะ FiveThirtyEight |
dark_background | พื้นหลังสีดำ |
classic | Matplotlib 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 ยาวมาก จึงไม่แสดงทั้งหมด)