1. 程式人生 > >簡說Python之Jupyter Notebook

簡說Python之Jupyter Notebook

[toc] 系統環境:`Ubuntu 18.04.1 LTS` Python使用的是虛擬環境:`virutalenv` Python的版本:`Python 3.6.9` ## 簡說Python之Jupyter Notebook ### 1.Jupyter Notebook ```python pip install -U ipywidgets "ipython[notebook]" ``` 啟用`ipywidgets`HTML掛件專案 ```python (zsdpy1) $ jupyter nbextension enable --py widgetsnbextension Enabling notebook extension jupyter-js-widgets/extension... - Validating: OK ``` 啟動`Jupyter ` ```python (zsdpy1) $ cd /home/zsd/work/ (zsdpy1) $ jupyter notebook --port 5000 --no-browser --ip="*" ``` 輸入地址:`http://172.30.xx.252:5000` ![](https://img2020.cnblogs.com/blog/1398629/202003/1398629-20200319101620932-399457170.png) `Jupyter Notebook`最大的優勢在於演示,可以用作於: * 專案說明文件,解釋和溝通 * PPT演示,很多資料分析Echarts,方便資料視覺化 * 個人技術的展示 如下: ![](https://img2020.cnblogs.com/blog/1398629/202003/1398629-20200319102026880-1040863593.png)\ Jupyter Notebook的Echarts應用 1.安裝pyecharts ``` pip install pyecharts ``` 升級方式: ``` $ pip install pyecharts -U ``` 2.應用展示 開源地址:https://github.com/pyecharts/pyecharts 展示程式碼: ```python from pyecharts.charts import Bar from pyecharts import options as opts bar =( Bar() .add_xaxis(["數學","語文","英語","物理","化學","生物"]) .add_yaxis("男生平均成績",[114,100,108,60,78,54]) .add_yaxis("女生平均成績",[90,110,120,54,65,48]) .set_global_opts(title_opts=opts.TitleOpts(title="某高校高考成績情況")) ) bar.render_notebook() ``` ![](https://img2020.cnblogs.com/blog/1398629/202003/1398629-20200319104111043-322029263.png) 地圖程式碼的演示: ```python from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.globals import ChartType, SymbolType c = ( Geo() .add_schema( maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"), ) .add( "", [("廣州", 55), ("北京", 66), ("杭州", 77), ("重慶", 88)], type_=ChartType.EFFECT_SCATTER, color="white", ) .add( "geo", [("廣州", "上海"), ("廣州", "北京"), ("廣州", "杭州"), ("廣州", "重慶")], type_=ChartType.LINES, effect_opts=opts.EffectOpts( symbol=SymbolType.ARROW, symbol_size=6, color="blue" ), linestyle_opts=opts.LineStyleOpts(curve=0.2), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Geo-Lines-background")) ) ``` ```python c.render_notebook() ``` ![](https://img2020.cnblogs.com/blog/1398629/202003/1398629-20200319104936213-1901925027.png) ![](https://img2020.cnblogs.com/blog/1398629/202003/1398629-20200319105048428-3552425