设置matplotlib的绘图风格

时间:2026-02-13 14:49:24

1、设定样式前可先查看matplotlib有哪些样式,使用函数plt.style.available查看可用的样式,结果列出了27种style,如下图。

设置matplotlib的绘图风格

2、设定样式需要使用函数:plt.style.use(),在括号中指定需要的样式:

例如:plt.style.use('ggplot')

然后再运行绘图代码:

x = np.linspace(0,2*np.pi,200)

y = np.cos(x)

plt.plot(x,y)

plt.title('cos函数')

设置matplotlib的绘图风格

3、再尝试seaborn风格:plt.style.use('seaborn')

设置matplotlib的绘图风格

4、下面是bmh风格:plt.style.use('bmh')

设置matplotlib的绘图风格

5、下面是classic风格:plt.style.use('classic')

设置matplotlib的绘图风格

© 2026 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com