離線狀態(tài)下在jupyter notebook中使用plotly實例
更新時間:2020年04月24日 08:59:16 作者:sujingclg
這篇文章主要介紹了離線狀態(tài)下在jupyter notebook中使用plotly實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
首先創(chuàng)建一個新的python3記錄,之后在開始位置輸入以下語句并執(zhí)行:
import plotly import plotly.offline as py py.init_notebook_mode(connected=False) import plotly.graph_objs as go
注意此時實際上是將plotly的庫文件寫在了ipynb文件內(nèi)部,因此保存后的ipynb文件會比較大,一般在5M以上.
補充知識:plotly 繪制離線圖例(折線)
我就廢話不多說了,還是直接看代碼吧!
#log.txt 1 9 15 2 9 16 1 10 17 2 10 18 1 9 19
#!/usr/bin/env python import plotly.offline as pltoff import plotly.graph_objs as go def line_plots(name="line_plots.html"): dataset = { 'x': [], 'y1': [], 'y2': [], 'y3': [] } with open("./log.txt") as f: i = 0 for line in f: items = line.split() dataset['x'].append(i) dataset['y1'].append(items[0]) dataset['y2'].append(items[1]) dataset['y3'].append(items[2]) i += 1 data_g = [] # 構建 數(shù)據(jù)關系,折線圖 x_y1 = go.Scatter( x=dataset['x'], y=dataset['y1'], mode='lines', name='lines') data_g.append(x_y1) x_y2 = go.Scatter( x=dataset['x'], y=dataset['y2'], mode='markers', name='markers') data_g.append(x_y2) x_y3 = go.Scatter( x=dataset['x'], y=dataset['y3'], mode='lines+markers', name='lines+markers') data_g.append(x_y3) # 設置圖表布局 layout = go.Layout(title="Line plots", xaxis={'title': 'X'}, yaxis={'title': 'Y'}) fig = go.Figure(data=data_g, layout=layout) # 生成離線html pltoff.plot(fig, filename=name) if __name__ == '__main__': line_plots()
以上這篇離線狀態(tài)下在jupyter notebook中使用plotly實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- VScode連接遠程服務器上的jupyter notebook的實現(xiàn)
- 如何實現(xiàn)在jupyter notebook中播放視頻(不停地展示圖片)
- jupyter notebook 實現(xiàn)matplotlib圖動態(tài)刷新
- 解決matplotlib.pyplot在Jupyter notebook中不顯示圖像問題
- 查看jupyter notebook每個單元格運行時間實例
- jupyter notebook中新建cell的方法與快捷鍵操作
- Jupyter Notebook折疊輸出的內(nèi)容實例
- jupyter notebook oepncv 顯示一張圖像的實現(xiàn)
相關文章
Python獲取linux主機ip的簡單實現(xiàn)方法
這篇文章主要介紹了Python獲取linux主機ip的簡單實現(xiàn)方法,涉及Python使用socket模塊調(diào)用shell命令的相關技巧,需要的朋友可以參考下2016-04-04Python Pillow Image.save 保存為jpg圖片壓縮問題
Pillow 庫支持多種圖片格式,Pillow 能夠很輕松地實現(xiàn)圖片格式之間的轉換。本文就來詳細的介紹一下Image.save的具體使用,感興趣的可以了解一下2021-11-11pytorch教程resnet.py的實現(xiàn)文件源碼分析
torchvision.models這個包中包含alexnet、densenet、inception、resnet、squeezenet、vgg等常用的網(wǎng)絡結構,并且提供了預訓練模型,可以通過簡單調(diào)用來讀取網(wǎng)絡結構和預訓練模型2021-09-09