如果您想在 Spyder 中开发您的情节图形,也许是因为 Spyder 出色的变量浏览器,您可以轻松地显示非交互式图像只需跑步fig.show()
。请注意,这是针对较新版本的plotly,您不必担心iplot
and plotly.offline
.
如果您想在浏览器中将您的图形显示为完全互动版本,只需运行:
import plotly.io as pio
pio.renderers.default='browser'
现在您的图形将显示在您的默认浏览器中。
要切换回在 Spyder 中生成图形,只需运行:
import plotly.io as pio
pio.renderers.default='svg'
您也可以使用检查其他选项pio.renderers?
:
Renderers configuration
-----------------------
Default renderer: 'svg'
Available rendere <...> wser', 'firefox', 'chrome', 'chromium', 'iframe',
'iframe_connected', 'sphinx_gallery']
你会发现更多细节here under Setting the default renderer
这是一个详细的例子
Code:
import plotly.graph_objects as go
import plotly.io as pio
#pio.renderers.default = 'svg'
pio.renderers.default = 'browser'
x = ['Product A', 'Product B', 'Product C']
y = [20, 14, 23]
fig = go.Figure(data=[go.Bar(
x=x, y=y,
text=y,
textposition='auto',
)])
fig.show()
Plot:
系统信息:
Python 3.7.6
Spyder 3.3.1
Plotly 3.2.0