您的位置 首页 > 数码极客

如何把图片转换成手绘风格 如何把图片转换成A4…

今天再介绍一个手绘工具(ma()),一行代码可将所有Matplotlib和Seaborn绘制的图形变为手绘风格。

ma()简介

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

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

ma()使用

如下,加with行代码即可,括号中参数按个人喜好决定是否设置~

with (scale=1, length=100, randomness=2): #with是临时使用一下,不影响其它图使用正常样式 绘图代码 。。。。。。 ()

ma()使用实例

以下参考:Python可视化25|seaborn绘制矩阵图

#支持seaborn import seaborn as sns iris_sns = ("iris") with (): g = ( iris_sns, hue='species', #按照三种花分类 palette=['#dc2624', '#2b4750', '#45a0a2']) (style='whitegrid') g.(12, 12) (style='whitegrid', font_scale=1.5)

以下参考:Python可视化29|matplotlib-饼图(pie)

import ma as plt with ( scale=4, #相对于不使用xkcd的风格图,褶皱的幅度 length=120, #褶皱长度 randomness=2): #褶皱的随机性 (dpi=150) patches, texts, autotexts = ( x=[1, 2, 3], #返回三个对象 labels=['A', 'B', 'C'], colors=['#dc2624', '#2b4750', '#45a0a2'], autopct='%.2f%%', explode=, 0, 0)) texts[1].set_size('20') #修改B的大小 #ma patches[0].set_alpha) #A组分设置透明度 patches[2].set_hatch('|') #C组分添加网格线 patches[1].set_hatch('x') ( patches, ['A', 'B', 'C'], #添加图例 title="Pie Learning", loc="center left", fontsize=15, bbox_to_anchor=(1, 0, 0.5, 1)) ('Lovely pie', size=20) ()

with (): from string import ascii_letters (dpi=150) patches, texts, autotexts = ( x=range(1, 12), labels=list(ascii_letters[26:])[0:11], colors=[ '#dc2624', '#2b4750', '#45a0a2', '#e87a59', '#7dcaa9', '#649E7D', '#dc8018', '#C89F91', '#6c6d6c', '#4f6268', '#c7cccf' ], autopct='%.2f%%', ) ( patches, list(ascii_letters[26:])[0:11], #添加图例 title="Pie Learning", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1), ncol=2, #控制图例中按照两列显示,默认为一列显示, )

以下参考:Python可视化|matplotlib12-垂直|水平|堆积条形图详解

import ma as plt import numpy as np with (): (dpi=150) labels = ['Jack', 'Rose', 'Jimmy'] year_2019 = np.arange(1, 4) year_2020 = np.arange(1, 4) + 1 bar_width = 0.4 ( np.arange(len(labels)) - bar_width / 2, #为了两个柱子一样宽 year_2019, color='#dc2624', width=bar_width, label='year_2019' #图例 ) ( np.arange(len(labels)) + bar_width / 2, year_2020, color='#45a0a2', width=bar_width, label='year_2020' #图例 ) (0, 3, step=1), labels, rotation=45) #定义柱子名称 (loc=2) #图例在左边

以下参考: Python可视化|matplotlib10-绘制散点图scatter

import ma as plt import numpy as np import pandas as pd from pandas import Series, DataFrame #数据准备 from sklearn import datasets iris = da() x, y = iris.data, iris.target pd_iris = ((x, y.reshape(150, 1))), columns=[ 'sepal length(cm)', 'sepal width(cm)', 'petal length(cm)', 'petal width(cm)', 'class' ]) with (): (dpi=150) #设置图的分辨率 #('Solarize_Light2') #使用Solarize_Light2风格绘图 iris_type = pd_iris['class'].unique() #根据class列将点分为三类 iris_name = iris.target_names #获取每一类的名称 colors = ['#dc2624', '#2b4750', '#45a0a2'] #三种不同颜色 markers = ['$\clubsuit, '.', '+'] #三种不同图形 for i in range(len(iris_type)): ( [pd_iris['class'] == iris_type[i], 'sepal length(cm)'], #传入数据x [pd_iris['class'] == iris_type[i], 'sepal width(cm)'], #传入数据y s=50, #散点图形(marker)的大小 c=colors[i], #marker颜色 marker=markers[i], #marker形状 #marker=ma(marker = markers[i],fillstyle='full'),#设置marker的填充 alpha=0.8, #marker透明度,范围为0-1 facecolors='r', #marker的填充颜色,当上面c参数设置了颜色,优先c edgecolors='none', #marker的边缘线色 linewidths=1, #marker边缘线宽度,edgecolors不设置时,该参数不起作用 label=iris_name[i]) #后面图例的名称取自label (loc='upper right')

Ref: https://matplotlib.org/stable/api/_as_gen/ma.html#ma

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何把图片转换成手绘风格,如何把图片转换成A4,如何将图片转换为手绘,如何将图片转换成A3”边界阅读