python 绘制手绘风格图

python 绘制手绘风格图

这个Matplotlib子函数特别简单,只有三个参数,别看参数少,但功能可不小

matplotlib.pyplot.xkcd(scale=1, #相对于不使用xkcd的风格图,褶皱的幅度
                       length=100, #褶皱长度
                       randomness=2#褶皱的随机性
                      )
import matplotlib.pyplot as plt

labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 35, 30, 35, 27]
men_std = [2, 3, 4, 1, 2]


width = 0.35       # the width of the bars: can also be len(x) sequence

fig, ax = plt.subplots()

ax.bar(labels, men_means, width, yerr=men_std, label='Men', color=plt.get_cmap('tab10')(range(5)))

ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')

plt.show()

with plt.xkcd():
    fig, ax = plt.subplots()
    ax.bar(labels, men_means, width, yerr=men_std, label='Men', color=plt.get_cmap('tab10')(range(5)))

    ax.set_ylabel('Scores')
    ax.set_title('Scores by group and gender')

    plt.show()

#支持seaborn
import seaborn as sns
iris_sns = sns.load_dataset("iris")

# 常规
g = sns.pairplot(
    iris_sns,
    hue='species',  #按照三种花分类
    palette=['#dc2624', '#2b4750', '#45a0a2'])
sns.set(style='whitegrid')
g.fig.set_size_inches(12, 12)
sns.set(style='whitegrid', font_scale=1.5)

# 手绘
with plt.xkcd():
    g = sns.pairplot(
        iris_sns,
        hue='species',  #按照三种花分类
        palette=['#dc2624', '#2b4750', '#45a0a2'])
    sns.set(style='whitegrid')
    g.fig.set_size_inches(12, 12)
    sns.set(style='whitegrid', font_scale=1.5)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TKIaA616-1668745282043)(C:/Users/wang/AppData/Roaming/Typora/typora-user-images/image-20220827235703718.png)]

with plt.xkcd():
    plt.figure(figsize=(15, 10))
    sns.violinplot( x=data["class"], y=data["speed"], linewidth=1, cmap=cmaps.Cat12_r)#palette="Set2") #also cmap=
    sns.set_theme(style="darkgrid", palette=None ,font='Times New Roman',font_scale=3)

t_theme(style=“darkgrid”, palette=None ,font=‘Times New Roman’,font_scale=3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地学万事屋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值