我正在Jupyter Notebook中使用plotly来制作等值线。我想绘制一个等值线,但它显示我的空输出。我正在使用离线plotly.In html它的genrated图表成功但当我尝试离线时它显示空输出。请告诉我如何解决这个错误。 这是我的代码
from plotly.graph_objs import * from plotly.offline import download_plotlyjs, init_notebook_mode, iplot from plotly.offline.offline import _plot_html init_notebook_mode(connected=True) for col in state_df.columns: state_df[col] = state_df[col].astype(str) scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\ [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']] state_df['text'] = state_df['StateCode'] + '<br>' +'TotalPlans '+state_df['TotalPlans'] data = [ dict( type='choropleth', colorscale = scl, autocolorscale = False, locations = state_df['StateCode'], z = state_df['TotalPlans'].astype(float), locationmode = 'USA-states', text = state_df['text'], marker = dict( line = dict ( color = 'rgb(255,255,255)', width = 2 ) ), colorbar = dict( title = "Millions USD" ) ) ] layout = dict( title = 'Plan by States', geo = dict( scope='usa', projection=dict( type='albers usa' ), showlakes = True, lakecolor = 'rgb(255, 255, 255)', ), ) fig = dict(data=data, layout=layout) plotly.offline.iplot(fig)
答案 0 :(得分:1)
您正在向dict
传递iplot
,这与文档相反,只能处理Figure
个对象而不是字典。
尝试
fig = Figure(data=[data], layout=layout)
它应该有用。