情节:如何检查V4的基本图形结构

问题描述 投票:1回答:1

对于较早版本的plotly,例如在Jupyterlab中,您可以简单地运行figure来检查图形的基础,如下所示:

输出:

{'data': [{'marker': {'color': 'red', 'size': '10', 'symbol': 104},
   'mode': 'markers+lines',
   'name': '1st Trace',
   'text': ['one', 'two', 'three'],
   'type': 'scatter',
   'x': [1, 2, 3],
   'y': [4, 5, 6]}],
 'layout': {'title': 'First Plot',
  'xaxis': {'title': 'x1'},
  'yaxis': {'title': 'x2'}}}

V4之前版本的代码:

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(x=[1,2,3], y=[4,5,6], marker={'color': 'red', 'symbol': 104, 'size': "10"},
                    mode="markers+lines",  text=["one","two","three"], name='1st Trace')

data=go.Data([trace1])
layout=go.Layout(title="First Plot", xaxis={'title':'x1'}, yaxis={'title':'x2'})
figure=go.Figure(data=data,layout=layout)
#py.iplot(figure, filename='pyguide_1')
figure

如果现在通过相似的设置执行相同的操作,则相同的方法将不会产生图形基础,而是绘制图形本身:

代码:

import pandas as pd
import plotly.graph_objects as go

trace1 = go.Scatter(x=[1,2,3], y=[4,5,6], marker={'color': 'red', 'symbol': 104},
                    mode="markers+lines",  text=["one","two","three"], name='1st Trace')  

figure = go.Figure(data=trace1)  

figure

输出:

enter image description here

[在许多方面,这类似于您用ggplot中的R构建和绘制图形的方式。而且由于plotly可用于RPython,所以我认为这毕竟是有道理的。但我真的很想知道如何访问该基本设置。

我尝试过的事情:] >>

我认为此更改是由于figure现在是plotly.graph_objs._figure.Figure,并曾经是字典(?)。因此figure['data']figure['layout']仍然是具有必要和有趣内容的字典:

figure['data']的输出

(Scatter({
     'marker': {'color': 'red', 'symbol': 104},
     'mode': 'markers+lines',
     'name': '1st Trace',
     'text': [one, two, three],
     'x': [1, 2, 3],
     'y': [4, 5, 6]
 }),)

figure['layout']的输出

Layout({
    'template': '...'
})

当然还有help(figure)dir(figure)之类的选项很有用,但输出却大不相同。

对于较早版本的plotly,例如在Jupyterlab中,您可以简单地运行图形来检查图形的基础,如下所示:Ouput:{'data':[{'marker':{'color':'red', 'size':'10','...

python plotly
1个回答
0
投票

我刚刚发现,“忘记” figure.show()的括号将为我提供所需的确切信息。因此,使用与问题中的代码类似的设置以及使用V4,只需运行figure.show将为您提供:

© www.soinside.com 2019 - 2024. All rights reserved.