1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python 3/前端 画图工具:Matplotlib canvajs pyecharts

Python 3/前端 画图工具:Matplotlib canvajs pyecharts

时间:2020-04-04 23:14:44

相关推荐

Python 3/前端 画图工具:Matplotlib canvajs pyecharts

之前我一直是用Matplotlib画图,写了挺多博客:

Python:matplotlib绘图时指定图像大小,放大图像matplotlib绘制平滑的曲线Matplotlib使用日期作为横坐标matplotlib 设置坐标轴单位

Matplotlib画图示例如下:

import matplotlib.pyplot as pltfrom pylab import mplmpl.rcParams['font.sans-serif'] = ['SimHei']x = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]y = [5, 20, 36, 10, 75, 90]plt.title("商家A")plt.bar(x, y)plt.show()

结果如图所示:

怎么说呢,用Matplotlib画图很朴实。

现在前端发展太快了,感觉这种图太朴素了,不够炫酷。

我现在经常使用canvajs画图,官网:Beautiful HTML5 JavaScript Charts

代码如下:

function draw() {var chart = new CanvasJS.Chart("chartContainer", {theme: "light2",title: {text: "商家A"},data: [{type: "bar",dataPoints: [ //array{label: "衬衫", y: 5},{label: "羊毛衫", y: 20},{label: "雪纺衫", y: 36},{label: "裤子", y: 10},{label: "高跟鞋", y: 75},{label: "袜子", y: 90},]}]});chart.render();}

效果如图所示:

从效果来看,明显炫酷多了。

最近发现了另外一个工具:pyecharts

这个工具是把echarts用Python进行操作,代码如下:

from pyecharts.charts import Barbar = Bar()bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])# render 会生成本地 HTML 文件,默认会在当前目录生成 render.html 文件# 也可以传入路径参数,如 bar.render("mycharts.html")bar.render()

效果图如下:

感觉echarts没有canvajs好看。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。