在matplotlib 中 提供了很多样式来美化绘图。
在plt.style.available中
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
print(plt.style.available)
plt.style.use('grayscale')
[out]:
['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', 'tableau-colorblind10', '_classic_test']
我们使用
plt.style.use()使用其中的一个样式,
x = np.arange(0, 10, 0.1)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()
下面,我们使用自带样式进行美化:
…略
我们也可以自定义。