matplotlib 은 다른 시각화 라이브러리와 달리 좀 더 본인이 원하는대로 기본설정을 바꾸어 사용하는데 용이하다. 그 중 기본 matplotlib스타일인 stylesheet을 설정하는 방법은 plt.style.use("스타일시트") 코드의 "스타일시트"에 위에서 출력한 목록 중 본인이 사용하고 싶은 스타일시트 이름을 넣으면 변경된다.
matplotlib을 import해주고 plt.style.available를 입력하면 matplotlib에서 사용할 수 있는 스타일시트 목록이 출력된다. 권장되는 style은 white시트이며, grid가 필요할 때는 추가하면 된다.
'default'를 시작으로 'bmh', 'classic', '_classic_test_patch', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark', 'seaborn-dark-palette', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'tableau-colorblind10'까지 각 스타일은 아래와 같이 표현된다.
import matplotlib.pyplot as plt
plt.style.available
['Solarize_Light2',
'_classic_test_patch',
'bmh',
'classic',
'dark_background',
'fast',
'fivethirtyeight',
'ggplot',
'grayscale',
'seaborn',
'seaborn-bright',
'seaborn-colorblind',
'seaborn-dark',
'seaborn-dark-palette',
'seaborn-darkgrid',
'seaborn-deep',
'seaborn-muted',
'seaborn-notebook',
'seaborn-paper',
'seaborn-pastel',
'seaborn-poster',
'seaborn-talk',
'seaborn-ticks',
'seaborn-white',
'seaborn-whitegrid',
'tableau-colorblind10']
import pandas as pd
import random
series = pd.Series(random.sample(range(100, 1000), 10),
index = list('matplotlib'))
styles = ['default', 'bmh', 'classic', '_classic_test_patch',
'dark_background', 'fast', 'fivethirtyeight', 'ggplot',
'grayscale', 'seaborn', 'seaborn-bright', 'seaborn-colorblind',
'seaborn-dark', 'seaborn-dark-palette', 'seaborn-darkgrid',
'seaborn-deep', 'seaborn-muted', 'seaborn-notebook',
'seaborn-paper', 'seaborn-pastel', 'seaborn-poster',
'seaborn-talk', 'seaborn-ticks', 'seaborn-white',
'seaborn-whitegrid', 'tableau-colorblind10',
'_classic_test_patch']
for style in styles:
plt.style.use(style)
plt.title('The type of style is ' + '"' + style + '"')
plt.bar(series.index, series.values)
plt.show()
'파이썬 > visualization' 카테고리의 다른 글
[파이썬/viz] Matplotlib Line Plot (0) | 2022.11.13 |
---|