离线状态下在jupyter notebook中使用plotly实例
作者:sujingclg 时间:2022-04-19 18:05:59
首先创建一个新的python3记录,之后在开始位置输入以下语句并执行:
import plotly
import plotly.offline as py
py.init_notebook_mode(connected=False)
import plotly.graph_objs as go
注意此时实际上是将plotly的库文件写在了ipynb文件内部,因此保存后的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 = []
# 构建 数据关系,折线图
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()
来源:https://blog.csdn.net/sujingclg/article/details/86934488
标签:离线,jupyter,notebook,plotly
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
简单代码实现可输入的下拉框功能(select)
2008-10-20 19:52:00
python仿evething的文件搜索器实例代码
2022-05-05 09:05:15
![](https://img.aspxhome.com/file/2023/3/99423_0s.png)
不成熟的标准化是我们唯一惧怕的
2008-08-15 18:55:00
关于Python解包知识点总结
2021-01-03 22:34:15
Python编程实现线性回归和批量梯度下降法代码实例
2021-10-13 07:33:27
![](https://img.aspxhome.com/file/2023/5/120915_0s.png)
Python PSO算法处理TSP问题详解
2022-12-02 02:39:24
![](https://img.aspxhome.com/file/2023/7/130777_0s.png)
用 SQL 脚本将 Access 导入 MSSQL 2000/2005 方法
2008-10-22 13:51:00
Python实现基于POS算法的区块链
2023-10-30 01:47:19
![](https://img.aspxhome.com/file/2023/1/67291_0s.png)
使用PyQt5设计GUI实现程序图形界面设计
2021-09-26 03:22:02
![](https://img.aspxhome.com/file/2023/1/121901_0s.jpg)
再谈 Web 默认字体
2009-11-24 12:48:00
Python3中str、bytes、bytearray转化
2023-01-11 23:29:30
python 合并文件的具体实例
2022-03-12 03:18:26
利用Python读取Excel表内容的详细过程
2022-10-24 05:43:33
![](https://img.aspxhome.com/file/2023/1/105361_0s.png)
Python实现的三层BP神经网络算法示例
2021-05-16 19:21:05
![](https://img.aspxhome.com/file/2023/0/98320_0s.png)
asp实现ACCESS数据库加密方法
2008-04-18 12:33:00
一篇文章带你了解python中的typing模块和类型注解
2023-08-05 21:37:02
Python实现生活常识解答机器人
2021-06-22 14:34:36
![](https://img.aspxhome.com/file/2023/6/70726_0s.png)
详解Django admin高级用法
2021-08-08 23:55:38
Python连接SQLServer2000的方法详解
2023-07-23 09:02:12
Python实现SMTP发送邮件详细教程
2021-05-10 03:01:01
![](https://img.aspxhome.com/file/2023/8/109578_0s.jpg)