问题描述
我正在尝试使用plotly进行一些可视化。 但是,当我尝试进行可视化时,总是会遇到以下错误。
以下是我的代码。
#Boxplot and histogram of Total Direct Variable Cost grouped by with or with Financial Class
import chart_studio.plotly as py
from plotly.offline import iplot
trace0 = go.Box(
y=healthcare.loc[healthcare['A'] == 'Inpatient']['B'],name = 'Inpatient',marker = dict(
color = 'rgb(214,12,140)',)
)
trace1 = go.Box(
y=healthcare.loc[healthcare['A'] == 'InBorn']['B'],name = 'InBorn',marker = dict(
color = 'rgb(0,128,128)',)
)
data = [trace0,trace1]
layout = go.Layout(
title = "CCCCCCCCCCCC"
)
fig = go.figure(data=data,layout=layout)
py.iplot(fig)
解决方法
我遇到了同样的问题,所以我将py.iplot(fig)
更改为fig.show()
阅读:https://plotly.com/python/troubleshooting/
对于 Jupyter 经典笔记本:
import plotly.io as pio
pio.renderers.default='notebook'
然后使用 fig.show() 如上所述。