Plotly的put_figure方法如何使用

528
2024/5/4 12:02:15
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

plotly中的put_figure方法用于将图形添加到指定的div元素中。其使用方法如下:

  1. 首先,创建一个图形对象,例如trace和layout等。

  2. 使用put_figure方法将图形添加到指定的div元素中。

示例代码如下:

import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, iplot

# 创建图形对象
trace = go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 11, 12, 13]
)

layout = go.Layout(
    title='Plotly Example'
)

fig = go.Figure(data=[trace], layout=layout)

# 将图形添加到指定的div元素中
div_id = "myDiv"
fig_json = fig.to_json()
iplot({'data': fig_json, 'layout': {}, 'config': {'displayModeBar': False}}, show_link=False)

在上面的示例中,我们首先创建了一个Scatter图形对象,然后使用put_figure方法将该图形添加到指定的div元素中。这样就可以将图形显示在指定的div元素中。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 怎么使用Plotly创建小提琴图