Toyplot:一个简洁、可爱的Python的交互式数据可视化绘图库

1 说明:
=====
【Toyplot:一个简洁、可爱的Python的交互式数据可视化绘图库】1.1 Toyplot是一个Python的交互式绘图库,可用于数据可视化、绘图、文字,用各种形式展示 。
1.2 为科学家和工程师们提供简洁的界面 。
1.3 可开发美丽的交互式动画,以满足电子出版和支持repoducibility的独特功能 。
1.4 创建最佳的数据图形"out-of-the-box" 。

Toyplot:一个简洁、可爱的Python的交互式数据可视化绘图库

文章插图
 
2 准备:
=====
2.1 官网:
https://github.com/sandialabs/toyplothttps://toyplot.readthedocs.io/en/stable/2.2 安装:
pip install toyplot#本机安装sudo pip3.8 install toyplot#推荐国内源安装sudo pip3.8 install -i https://mirrors.aliyun.com/pypi/simple toyplot2.3 环境:
华为笔记本电脑、深度deepin-linux操作系统、谷歌浏览器、python3.8和微软vscode编辑器 。
3 折线图:
=======
3.1 本代码:为注释版
#line==折线图import toyplot as tpx=['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,) #方法一,画布大小设置#方法二:style=类似与css设置#canvas = tp.Canvas("6in", "6in", style={"background-color":"pink"})#坐标轴axes的标签名axes = canvas.cartesian(xlabel='序号',ylabel='data')#线条颜色color设置#mark = axes.plot(x, y,color='red')#1组颜色设置mark = axes.plot(x, y,color=['red','green'])#1组颜色设置#水平图例==horizontal-legendsmarkers = [mark + tp.marker.create(shape="o") for mark in mark.markers]axes.label.text = markers[0] + "dog" + markers[1] + "pig"#浏览器自动打开,推荐这种import toyplot.browsertp.browser.show(canvas)#生成pdf#import toyplot.pdf#tp.pdf.render(canvas, "/home/xgj/Desktop/toyplot/1-line.pdf")#生成png图片#import toyplot.png#tp.png.render(canvas, "/home/xgj/Desktop/toyplot/1-line.png")#生成html#import toyplot.html#tp.html.render(canvas, "/home/xgj/Desktop/toyplot/1-line.html")'''#生成svg图片import toyplot.svgsvg = tp.svg.render(canvas)svg.attrib["class"] = "MyCustomClass"import xml.etree.ElementTree as xmlwith open("/home/xgj/Desktop/toyplot/1-line.svg", "wb") as file:file.write(xml.tostring(svg))'''3.2 上述代码简洁版:
#line==折线图import toyplot as tpx=['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,) #画布大小设置#坐标轴axes的标签名axes = canvas.cartesian(xlabel='序号',ylabel='data')#线条颜色color设置mark = axes.plot(x, y,color=['red','green'])#水平图例==horizontal-legendsmarkers = [mark + tp.marker.create(shape="o") for mark in mark.markers]axes.label.text = markers[0] + "dog" + markers[1] + "pig"#浏览器自动打开,推荐这种import toyplot.browsertp.browser.show(canvas)3.3 操作和效果图:
Toyplot:一个简洁、可爱的Python的交互式数据可视化绘图库

文章插图
 
4 散点图:
========
4.1 代码:
import toyplotcanvas = toyplot.Canvas(width=500, height=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")marks = []for label in ["0", "55", "100"]:marks.Append(toyplot.marker.create(shape="o",label=label,size=25,))m2 = axes.scatterplot([0, 1, 2], [1, 2, 3], marker=marks)#浏览器自动打开,推荐这种import toyplot.browsertoyplot.browser.show(canvas)4.2 图:
Toyplot:一个简洁、可爱的Python的交互式数据可视化绘图库

文章插图
 
5 垂直堆砌柱状图:
==============
5.1 代码:
#bars==垂直堆砌柱状图=vsbarimport toyplot as tpx=['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,) #方法一,画布大小设置#方法二:style=类似与css设置#canvas = tp.Canvas("6in", "6in", style={"background-color":"pink"})#坐标轴axes的标签名axes = canvas.cartesian(xlabel='序号',ylabel='data')#线条颜色color设置,2组颜色设置mark = axes.bars(x, y,color=['red','green'])#水平图例==horizontal-legendsmarkers = [mark + tp.marker.create(shape="o") for mark in mark.markers]axes.label.text = markers[0] + "dog" + markers[1] + "pig"#浏览器自动打开,推荐这种import toyplot.browsertp.browser.show(canvas)


推荐阅读