Python改变画图风格

其他: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')

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值