对于旧版本的plotly,例如在 Jupyterlab 中,您可以简单地运行figure
像这样检查你的图形的基础知识:
Ouput:
{'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
如果您现在使用类似的设置执行相同的操作,则相同的方法将不会生成图形基础知识,而是绘制图形本身:
Code:
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
Output:
在许多方面,这类似于您使用以下命令构建和绘制图形的方式:ggplot
in R
。因为情节对于两者都可用R
and Python
我认为这毕竟是有道理的。但我真的很想知道如何访问该基本设置。
我尝试过的:
我认为这种变化是由于以下事实figure
现在是一个plotly.graph_objs._figure.Figure
曾经是一本字典(?)。所以figure['data']
and 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)
and dir(figure)
很有帮助,但会产生非常不同的输出。