1描述:=====1.1Toyplot是Python中的一个交互式绘图库,可以用于数据可视化、绘图、文本以及各种形式的显示。1.2为科学家和工程师提供简洁的界面。1.3可开发精美的互动动画,以满足电子出版和支持再生产的独特功能。1.4创建“开箱即用”的最佳数据图形。2准备:=====2.1官方网站:安装:pip安装玩具图#本地安装sudopip3.8安装玩具
1描述:
=====
1.1 Toyplot是Python中的一个交互式绘图库,可以用于数据可视化、绘图、文本以及各种形式的显示。
1.2为科学家和工程师提供简洁的界面。
1.3可开发精美的互动动画,以满足电子出版和支持再生产的独特功能。
1.4创建“开箱即用”的最佳数据图形。
2准备:
=====
2.1官方网站:
https://github.com/sandialabs/toyplot
https://toyplot.readthedocs.io/en/stable/
2.2安装:
pip安装玩具图
#本地安装
sudo pip3.8安装玩具图
#推荐的国内源安装
sudo pip3.8安装-I https://mirrors.aliyun.com/pypi/simple玩具图
2.3环境:
华为笔记本电脑,deepin-linux操作系统,谷歌浏览器,python3.8和微软vscode编辑器。
三折线图:
=======
3.1此代码是一个注释版本。
#line==折线图
将toyplot导入为tp
x=['1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6']
#y=[31,22,55,41,66,17] #1组数据
Y = [[31,22],[22,17],[55,34],[41,28],[66,43],[17,36]] # 2组数据。
Canvas = tp.canvas (width = 300,height = 300,)#方法一,画布大小设置。
#方法2: style=类似于css设置
#画布= tp。Canvas("6in "," 6in ",style = { " background-color ":" pink " })
#轴的标签名称
Axes = canvas.cartesian(xlabel= '序列号',ylabel= '数据')
#线条颜色颜色设置
# mark =轴。plot (x,y,color =' red') # 1组颜色设置
标记=轴。plot (x,y,color = ['red ',' green']) # 1组颜色设置。
#水平图例= =水平图例
markers =[mark+TP . marker . create(shape = " o ")for mark in mark . markers]
axes.label.text = markers[0] +"狗"+ markers[1] +"猪"
#建议浏览器自动打开。
导入toyplot .浏览器
tp.browser.show(画布)
#生成pdf
#进口toyplot.pdf
#tp.pdf.render(canvas,“/home/xgj/Desktop/toy plot/1-line . pdf”)
#生成png图片
#进口toyplot.png
#tp.png.render(canvas,"/home/xgj/Desktop/toy plot/1-line . png ")
#生成html
#进口toyplot.html
#tp.html.render(canvas,"/home/xgj/Desktop/toy plot/1-line . html ")
'''
#生成svg图片
导入toyplot.svg
svg = tp.svg.render(画布)
SVG . attrib[" class "]= " MyCustomClass "
将xml.etree.ElementTree作为xml导入
打开("/home/xgj/Desktop/toy plot/1-line . SVG "," wb ")作为文件:
file.write(xml.tostring(svg))
'''
3.2上述代码的简明版本:
#line==折线图
将toyplot导入为tp
x=['1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6']
Y = [[31,22],[22,17],[55,34],[41,28],[66,43],[17,36]] # 2组数据。
Canvas = tp.canvas (width = 300,height = 300,)# Canvas大小设置。
#轴的标签名称
Axes = canvas.cartesian(xlabel= '序列号',ylabel= '数据')
#线条颜色颜色设置
mark = axes.plot(x,y,color=['red ',' green'])
#水平图例= =水平图例
markers =[mark+TP . marker . create(shape = " o ")for mark in mark . markers]
axes.label.text = markers[0] +"狗"+ markers[1] +"猪"
#建议浏览器自动打开。
导入toyplot .浏览器
tp.browser.show(画布)
3.3操作和效果图:
4散点图:
========
4.1代码:
进口玩具图
画布=玩具图。画布(宽度=500,高度=500)
axes = canvas.cartesian()
m0 = axes.scatterplot([0,1,2],[0,1,2],size=25)
m1 = axes.text([0,1,2],[0,1,2],["0 "," 55 "," 100"],color="red ")
标记= []
对于[“0”、“55”、“100”]中的标签:
marks . append(toy plot . marker . create(
shape="o ",
label =标签,
尺寸=25,
))
m2 =轴.散点图([0,1,2],[1,2,3],标记=记号)
#建议浏览器自动打开。
导入toyplot .浏览器
toyplot.browser.show(画布)
4.2图:
5垂直叠加直方图:
==============
5.1代码:
# bars = =垂直堆积直方图=vsbar
将toyplot导入为tp
x=['1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6']
#y=[31,22,55,41,66,17] #1组数据
Y = [[31,22],[22,17],[55,34],[41,28],[66,43],[17,36]] # 2组数据。
Canvas = tp.canvas (width = 300,height = 300,)#方法一,画布大小设置。
#方法2: style=类似于css设置
#画布= tp。Canvas("6in "," 6in ",style = { " background-color ":" pink " })
#轴的标签名称
Axes = canvas.cartesian(xlabel= '序列号',ylabel= '数据')
#线条颜色颜色设置,2组颜色设置
mark = axes.bars(x,y,color=['red ',' green'])
#水平图例= =水平图例
markers =[mark+TP . marker . create(shape = " o ")for mark in mark . markers]
axes.label.text = markers[0] +"狗"+ markers[1] +"猪"
#建议浏览器自动打开。
导入toyplot .浏览器
tp.browser.show(画布)
5.2图:
6色条:
=======
6.1代码:
#色阶
进口数量
进口玩具图
colormap = toy plot . color . linear map(toy plot . color . palette(),domain_min=0,domain_max=8)
画布=玩具图。画布(宽度=400,高度=100)
axis = canvas . Color _ Scale(colormap,label="Color Scale ",scale="linear ")
axis . axis . ticks . locator = toy plot . locator . extended(format = " {:. 1f } ")
#建议浏览器自动打开。
导入toyplot .浏览器
toyplot.browser.show(画布)
6.2图:
7表格-heperlinks:
==============
7.1表格框图和链接以及图形文本。
7.2代码:
#表格-heperlinks
进口数量
进口玩具图
canvas,table = toyplot.table(行=4,列=4)
table.cells.grid.hlines[...] = "单身"
table.cells.grid.vlines[...] = "单身"
#填充颜色
table.cells.cell[1,1]。style = {"fill ":"深红色" }
#您可以指定一个链接地址
table.cells.cell[1,1]。hyperlink = " http://toy plot . readthedocs . io "
table.cells.cell[2,2]。style = {"fill":"seagreen"}
#您可以指定一个链接地址
table.cells.cell[2,2]。hyperlink = " http://www . Sandia . gov "
表格.单元格.单元格[3,3]。style = {"fill":"royalblue"}
表格.单元格.单元格[3,3]。title = "这是一个细胞!"
#建议浏览器自动打开。
导入toyplot .浏览器
toyplot.browser.show(画布)
7.3图:
8高级绘图的动态散点图:
====================
8.1代码:
#散布动画
进口数量
x = numpy.random.normal(大小=100)
y = numpy . random . normal(size = len(x))
进口玩具图
画布=玩具图。画布(300,300)
axes = canvas.cartesian()
mark = axes.scatterplot(x,y,size=10)
对于canvas.frames中的帧(len(x) + 1):
如果frame.number == 0:
对于范围内的I(len(x)):
frame.set_datum_style(mark,0,I,style={"opacity":0.1})
否则:
frame.set_datum_style(mark,0,frame.number - 1,style={"opacity":1.0})
#另存为mp4
#toyplot.mp4.render(canvas,"/home/xgj/Desktop/toy plot/test . MP4 ",progress=progress)
#建议浏览器自动打开。
导入toyplot .浏览器
toyplot.browser.show(画布)
8.2效果图:
= = =自己整理分享= = =
喜欢的人,请点赞、关注、评论、转发、收藏。
赠送20本心理学电子书,添加 微信:56163509 备注:心理学!
本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 sumchina520@foxmail.com 举报,一经查实,本站将立刻删除。
如若转载,请注明出处:https://www.xinli1988.com/45643.html
如若转载,请注明出处:https://www.xinli1988.com/45643.html