matplotlib有一些预置的样式,其中有一种样式叫"ggplot",模仿R中的图表包ggplot

plt.style.use('ggplot')

自定义样式文件

创建样式文件mpl_configdir/stylelib/presentation.mplstyle

axes.titlesize : 24
axes.labelsize : 20
lines.linewidth : 3
lines.markersize : 10
xtick.labelsize : 16
ytick.labelsize : 16

使用自定义样式

>>> import matplotlib.pyplot as plt
>>> plt.style.use('presentation')

样式表也可以组合使用

>>> import matplotlib.pyplot as plt
>>> plt.style.use(['dark_background', 'presentation'])

临时样式

with plt.style.context(('dark_background')):
    plt.plot(np.sin(np.linspace(0, 2 * np.pi)), 'r-o')
plt.show()

调整样式参数

import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.color'] = 'r'
plt.plot(data)

results matching ""

    No results matching ""