Mimesis库一个生成30种语言假数据的Python库
1说明:
1。1Mimesis库:生成假数据的一个Python库。
1。2支持30种语言(包括中文);可以生成20类数据;包括地址、编码、日期、食物、人名、科学数据等等。
1。3官网代码有误,进行修改,实现原有功能。
1。4熟悉matplotlib的柱状图制作。
2准备:
2。1github:https:github。comlkgeimfarimimesis
2。2环境:
华为笔记本电脑、深度deepinlinux操作系统、谷歌浏览器、python3。8和微软vscode编辑器。
2。3安装:pipinstallmimesis本机安装sudopip3。8installmimesis
3官网教程:
3。1原代码:注意官网的这段代码有报错,估计自己升级后并未修改。frommimesisimportPersonaldePersonal(de)icPersonal(is)de。fullname()SabrinaGutermuthic。fullname()Rsarlindsdttir
3。2mimesis文件夹下的mimesisinit。py中29行提示
3。3修改代码:这样格式importmimesis导入模块gmimesis。Generic(en)格式为英语g。person。fullname()TamekiaByrd
3。4小结和延伸:importmimesis导入模块gmimesis。Generic(de)德语;DE是Deutsch的缩写gmimesis。Generic(is)冰岛文gmimesis。Generic(ru)俄罗斯文gmimesis。Generic(ja)日文gmimesis。Generic(ko)韩文gmimesis。Generic(zh)中文g。person。fullname()嘉浩厉其实就是‘厉嘉浩’
4以中文为例子:
4。1代码:importmimesisgmimesis。Generic(zh)中文g。datetime。month()g。food。fruit()g。address。address()g。numbers。integernumber()g。numbers。integers()
4。2操作效果图:
4。3结果:〔1〕importmimesis。。。〔2〕g。datetime。month()二月〔3〕g。food。fruit()甜瓜〔4〕g。address。address()仓埠五条1183号〔5〕g。numbers。integernumber()824〔6〕g。numbers。integers()〔2,2,2,1,5,5,2,7,3,0〕
5假数据可视化:matplotlib实现柱状图举例
5。1代码:importmatplotlib。pyplotaspltimportmimesisgmimesis。Generic(zh)中文sizesg。numbers。integers()生成随机组假数据,默认10组plt。bar(range(len(sizes)),sizes)plt。show()
5。2图:
5。3复习一下matplotlib的颜色设置:
color〔‘r’,‘g’,‘b’,‘c’,‘m’,‘y’,‘k’,
‘darkorange’,‘lightgreen’,‘plum’,‘tan’,‘grey’,‘gold’,‘darkviolet’,‘turquoise’,
‘khaki’,‘pink’,‘skyblue’,‘lawngreen’,‘salmon’〕
5。4修改后并有注释代码:importmatplotlib。pyplotaspltimportmimesisgmimesis。Generic(zh)中文sizesg。numbers。integers()默认10组参数:start0,end10,n10从1到10,随机生成5组数据sizesg。numbers。integers(start1,end10,n5)plt。bar(range(len(sizes)),sizes)默认柱的颜色为蓝色plt。bar(range(len(sizes)),sizes,fcr)指定柱的颜色为rred红色rred红色,ggreen绿色,bblue蓝色,yyellow黄色c蒂芙尼蓝plt。bar(range(len(sizes)),sizes,colorrgbyc)指定5组不同颜色plt。title(bar)plt。show()
5。5图:
5。6高级一点的代码:importmatplotlib。pyplotaspltimportmimesisgmimesis。Generic(zh)中文随机产生数值yg。numbers。integers(start1,end10,n7)namelist〔Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday〕colorlist〔r,g,b,y,c,pink,tan〕xrange(len(y))plt。bar(x,y,colorcolorlist,ticklabelnamelist)fora,binzip(x,y):plt。text(a,b0。3,。3fb,hacenter,vabottom,fontsize15)柱子顶部下(内)plt。text(a,b0。1,。3fb,hacenter,vabottom,fontsize15)柱子顶部上(外)plt。title(bar)plt。show()
5。7图:
自己整理并分享出来
喜欢的人,请点赞、关注、评论、转发和收藏。