Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tìm tên style có sẵn trong Matplotlib

Để liệt kê tất cả tên style có sẵn trong Matplotlib:

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

Ví dụ mã nguồn

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

Kết quả

Dictionary chứa các style: 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-dark-palette', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'tableau-colorblind10'.

{'bmh': RcParams({...}), 'classic': RcParams({...}), 'dark_background': RcParams({...}), ...}

Cách sử dụng style:

plt.style.use('seaborn-v0_8-whitegrid')
# hoặc
with plt.style.context('ggplot'):
    plt.plot(...)

Để xem tên style đơn giản: print(plt.style.available).