Python
版本爲 Python 3.6
Docker 拉取鏡像 --> 運行鏡像 --> 更新 Zeppelin 的 Python 版本(默認是 3.5)
更新 Python 版本後安裝對應的 pip --> 安裝 pyecharts --> 運行 pyecharts 代碼
複製代碼
一、Docker 拉取 Zeppelin 的鏡像(這裏不作過多 Docker 環境搭建的簡介, 主要介紹怎麼在 Zeppelin 中使用 pyecharts)html
docker pull apache/zeppelin:0.8.1
(目前最新版本是 0.8.1)二、簡單模式運行 Zeppelin (簡單模式的意思就是沒有用 docker 的 volume 掛在文件目錄出來, 畢竟只是演示😄)python
docker run -itd -p 12000:8080 --rm --name zeppelin apache/zeppelin:0.8.1
映射 12000 端口,啓動以後稍微等待一會初始化,打開瀏覽器訪問 127.0.0.1:12000
便可以看見 Zeppelin 的主頁了。
三、建立一個基於 shell
命令的 notebook
(解釋器選擇框裏面顯示的是 sh
, 以下圖所示) linux
%sh
add-apt-repository ppa:jonathonf/python-3.6 && apt-get update && apt-get -y install python3.6
複製代碼
%sh
python3.6 -V
複製代碼
%sh
which python3.6
/usr/bin/python3.6
複製代碼
具體操做以下圖所示: git
四、安裝 Python 3.6
的 pip
和 pyecharts
github
shell
的 notebook
進行安裝也能夠在前一個 notebook
中繼續操做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
複製代碼
%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)
複製代碼
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
複製代碼
五、運行 pyecharts
的測試代碼docker
python
代碼的 notebook
%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),
)
)
# 下面的 print 中的 %html 是 Zeppelin 輸出 HTML 代碼的關鍵字, 務必保留.
html_content = bar.overlap(line).render_embed()
print("%html {}".format(html_content))
複製代碼
d8yy