- issue 链接
- pyecharts 的官方文档
- 附上 pyecharts 的 Github 仓库地址: github.com/pyecharts/p…
- 顺便附上个人的 Github 地址: github.com/sunhailin-L…
大致流程
- 接下来更新的
Python版本为Python 3.6
Docker 拉取镜像 --> 运行镜像 --> 更新 Zeppelin 的 Python 版本(默认是 3.5) 更新 Python 版本后安装对应的 pip --> 安装 pyecharts --> 运行 pyecharts 代码 复制代码
具体使用流程(过程中的 notebook json 会在文末附上下载链接)
-
1、 Docker 拉取 Zeppelin 的镜像(这里不做过多 Docker 环境搭建的简介, 主要介绍怎么在 Zeppelin 中使用 pyecharts)
docker pull apache/zeppelin:0.8.1
-
2、简单模式运行 Zeppelin (简单模式的意思就是没有用 docker 的 volume 挂在文件目录出来, 毕竟只是演示:smile:)
-
docker run -itd -p 12000:8080 --rm --name zeppelin apache/zeppelin:0.8.1映射 12000 端口,启动之后稍微等待一会初始化,打开浏览器访问127.0.0.1:12000即可以看见 Zeppelin 的主页了。
-
-
3、创建一个基于
shell命令的notebook(解释器选择框里面显示的是sh, 如下图所示)- 3.1、更新 Python 版本(下载过程中可能会出错,多重试几次就好了)
%sh add-apt-repository ppa:jonathonf/python-3.6 && apt-get update && apt-get -y install python3.6 复制代码
- 3.2、校验是否安装成功
%sh python3.6 -V 复制代码
- 3.3、输出一下 Python 3.6 的命令路径(替换解释器路径需要使用)
%sh which python3.6 /usr/bin/python3.6 复制代码
- 3.4、更新 Zeppelin 的 Python 解释器()
具体操作如下图所示:
-
4、安装
Python 3.6的pip和pyecharts- 注: 新建一个
shell的notebook进行安装也可以在前一个notebook中继续操作 - 4.1、安装
pip
%sh wget https://github.com/pypa/pip/archive/19.1.1.tar.gz && tar -zxf 19.1.1.tar.gz cd ./pip-19.1.1 && python3.6 setup.py install 复制代码
- 4.2、校验是否安装成功
%sh pip3.6 -V pip 19.1.1 from /usr/local/lib/python3.6/dist-packages/pip-19.1.1-py3.6.egg/pip (python 3.6) 复制代码
- 4.3、安装
pyecharts
%sh pip3.6 install pyecharts # 如下所示即安装成功 Collecting pyecharts Downloading https://files.pythonhosted.org/packages/07/50/ab3811620082732ca9efed79ea4cd77c6f8355439ac427e4eae952bc67c8/pyecharts-1.2.1-py3-none-any.whl (144kB) Collecting prettytable (from pyecharts) Downloading https://files.pythonhosted.org/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2 Collecting jinja2 (from pyecharts) Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB) Collecting MarkupSafe>=0.23 (from jinja2->pyecharts) Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl Building wheels for collected packages: prettytable Building wheel for prettytable (setup.py): started Building wheel for prettytable (setup.py): finished with status 'done' Stored in directory: /root/.cache/pip/wheels/80/34/1c/3967380d9676d162cb59513bd9dc862d0584e045a162095606 Successfully built prettytable Installing collected packages: prettytable, MarkupSafe, jinja2, pyecharts Successfully installed MarkupSafe-1.1.1 jinja2-2.10.1 prettytable-0.7.2 pyecharts-1.2.1 复制代码
- 注: 新建一个
-
5、运行
pyecharts的测试代码-
目前
pyecharts 1.2.1版本中暂时还没有zeppelin的渲染方法,方法将在下一个版本中进行更新。目前先通过一个比较不优雅的方式进行渲染 -
新建一个
python代码的notebook -
5.1、运行代码示例
%python import pyecharts.options as opts from pyecharts.charts import Bar, Line x_data = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"] bar = ( Bar(init_opts=opts.InitOpts(width="1600px", height="800px")) .add_xaxis(xaxis_data=x_data) .add_yaxis( series_name="蒸发量", yaxis_data=[ 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3, ], label_opts=opts.LabelOpts(is_show=False), ) .add_yaxis( series_name="降水量", yaxis_data=[ 2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3, ], label_opts=opts.LabelOpts(is_show=False), ) .extend_axis( yaxis=opts.AxisOpts( name="温度", type_="value", min_=0, max_=25, interval=5, axislabel_opts=opts.LabelOpts(formatter="{value} °C"), ) ) .set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=True, trigger="axis", axis_pointer_type="cross"), xaxis_opts=opts.AxisOpts( type_="category", axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow") ), yaxis_opts=opts.AxisOpts( name="水量", type_="value", min_=0, max_=250, interval=50, axislabel_opts=opts.LabelOpts(formatter="{value} ml"), axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), ) ) line = ( Line() .add_xaxis(xaxis_data=x_data) .add_yaxis( series_name="平均温度", yaxis_index=1, y_axis=[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2], label_opts=opts.LabelOpts(is_show=False), ) ) bar.overlap(line).render("mixed_bar_and_line.html") # 此时 Zeppelin 会有生成的 html 的文件路径(下面代码会用到) '/zeppelin/mixed_bar_and_line.html' 复制代码- 5.2、渲染生成的
html文件(后期版本会直接返回生成的html代码就可以直接渲染了)- 这里主要用到的是 Zeppelin 中渲染 html 的关键字,具体文档见右边Zeppelin 文档
%python html_file = open("/zeppelin/mixed_bar_and_line.html", "r", encoding="utf-8") html_content = html_file.read() print("%html " + html_content) 复制代码- 生成的图例( 可以交互 )
-
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- RecyclerView使用指南(一)—— 基本使用
- 如何使用Meteorjs使用URL参数
- 使用 defer 还是不使用 defer?
- 使用 Typescript 加强 Vuex 使用体验
- [译] 何时使用 Rust?何时使用 Go?
- UDP协议的正确使用场合(谨慎使用)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Remote
Jason Fried、David Heinemeier Hansson / Crown Business / 2013-10-29 / CAD 26.95
The “work from home” phenomenon is thoroughly explored in this illuminating new book from bestselling 37signals founders Fried and Hansson, who point to the surging trend of employees working from hom......一起来看看 《Remote》 这本书的介绍吧!