其他:Seaborn画图风格:https://matplotlib.org/gallery/index.html
查看可用的风格
import pandas as pd
style = pd.Series(plt.style.available)
style
0 Solarize_Light2
1 _classic_test_patch
2 bmh
3 classic
4 dark_background
5 fast
6 fivethirtyeight
7 ggplot
8 grayscale
9 seaborn
10 seaborn-bright
11 seaborn-colorblind
12 seaborn-dark
13 seaborn-dark-palette
14 seaborn-darkgrid
15 seaborn-deep
16 seaborn-muted
17 seaborn-notebook
18 seaborn-paper
19 seaborn-pastel
20 seaborn-poster
21 seaborn-talk
22 seaborn-ticks
23 seaborn-white
24 seaborn-whitegrid
25 tableau-colorblind10
dtype: object
使用 use 方法改变全局绘图风格
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.plot(x, x, label = 'liner')
plt.plot(x, x**2, label = 'quadratic')
plt.plot(x, x**3, label = 'cubic')
使用 with 方法临时改变绘图风格
- 只有在代码块内的部分才会被改变
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2, 100)
with plt.style.context('seaborn'):
pass
plt.plot(x, x, label = 'liner')
plt.plot(x, x**2, label = 'quadratic')
plt.plot(x, x**3, label = 'cubic')
恢复默认的风格
- 默认风格为 ‘default’,在列表中不显示
import matplotlib.pyplot as plt
plt.style.use('default')
plt.plot(x, x, label = 'liner')
plt.plot(x, x**2, label = 'quadratic')
plt.plot(x, x**3, label = 'cubic')