Farman Ali
Farman Ali

Reputation: 1

Jupyter Notebook not ploting output using plotly

I am working on choropleth using plotly in Jupyter Notebook.I want to plot choropleth but its showing me empty output.I am working with offline plotly.In html its genrated chart successfuly but when i tried offline it shows me empty output.please tell me how i solve this error. here is my code

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)

Upvotes: 0

Views: 868

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31659

You are passing a dictionary to iplot which in contradiction to the documentation can handle only Figure objects and not dictionaries.

Try

fig = Figure(data=[data], layout=layout)

and it should work.

Upvotes: 1

Related Questions