Matplotlib库提供的style.use()
函数可以为创建的图形设置合适的美学风格。
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('classic')
rng = np.random.RandomState(0) # 随机数种子
a = 100
x = rng.randn(a)
y = rng.randn(a)
t = plt.scatter(x, y)
plt.show()
更换风格1
plt.style.use('seaborn-white')
更换风格2
plt.style.use('ggplot')
还有许多其他风格:
运行如下代码:
print(plt.style.available)
得到所有支持的风格:
['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight',
'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind',
'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid',
'seaborn-deep', 'seaborn-muted', 'seaborn-notebook',
'seaborn-paper', 'seaborn-pastel', 'seaborn-poster',
'seaborn-talk', 'seaborn-ticks', 'seaborn-white',
'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', '_classic_test']