Python Jupyter笔记本未使用plotly打印输出
我正在Jupyter笔记本中使用plotly处理choropleth。我想打印choropleth,但它显示空输出。我正在脱机plotly处理。在html中,它的生成图表成功,但当我尝试脱机时,它显示空输出。请告诉我如何解决此错误。 这是我的密码 您正在向iplot传递一个字典,它与文档相反,只能处理地物对象而不能处理字典 试一试 它应该会起作用Python Jupyter笔记本未使用plotly打印输出,python,jupyter-notebook,jupyter,plotly,Python,Jupyter Notebook,Jupyter,Plotly,我正在Jupyter笔记本中使用plotly处理choropleth。我想打印choropleth,但它显示空输出。我正在脱机plotly处理。在html中,它的生成图表成功,但当我尝试脱机时,它显示空输出。请告诉我如何解决此错误。 这是我的密码 您正在向iplot传递一个字典,它与文档相反,只能处理地物对象而不能处理字典 试一试 它应该会起作用 from plotly.graph_objs import * from plotly.offline import download_plotlyj
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)
fig = Figure(data=[data], layout=layout)