















import plotly.express as px
# 创建一个示例图表
fig = px.scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], title="示例散点图")
# 保存为 HTML 文件
fig.write_html("scatter_plot.html")
import plotly.express as px
# 创建一个示例图表
fig = px.scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], title="示例散点图")
html_str = fig.to_html(full_html=False) # 仅生成<div>片段,不含完整页面结构
print(html_str) # 可嵌入其他HTML文档或Jinja2模板
import plotly.express as px
# 创建一个示例曲线图
fig = px.line(x=[1, 21, 32, 40], y=[110, 11, 120, 13], title="示例曲线图")
# 保存为 HTML 文件
fig.write_html("line_plot.html")
import plotly.express as px
fig = px.line(
x=[1, 21, 32, 40],
y=[110, 11, 120, 13],
title="示例曲线图",
markers=True, # 显示数据点
line_shape='spline', # 线条形状:'linear'、'spline'、'hv'、'vh'、'hvh'、'vhv'
color_discrete_sequence=["#1f77b4"] # 自定义线条颜色
)
fig.write_html("line_plot.html")
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。