1
votes

here is a link to my data https://docs.google.com/document/d/1oIiwiucRkXBkxkdbrgFyPt6fwWtX4DJG4nbRM309M20/edit?usp=sharing

My problem is that when I run this in a Jupyter Notebook. I get just the USA map with the colour bar and the lakes in blue. No data is on the map, not the labels nor the actual z data.

Here is my header:

import plotly.graph_objs as go 
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

%matplotlib inline
init_notebook_mode(connected=True) # For Plotly For Notebooks
cf.go_offline() # For Cufflinks For offline use


    %matplotlib inline
init_notebook_mode(connected=True) # For Plotly For Notebooks
cf.go_offline() # For Cufflinks For offline use

Here is my data and layout:

data = dict(type='choropleth',
            locations = gb_state['state'],
            locationmode = 'USA-states',
            colorscale = 'Portland',
            text =gb_state['state'],
            z = gb_state['beer'],
            colorbar = {'title':"Styles of beer"}
            ) 
data

layout = dict(title = 'Styles of beer by state',
              geo = dict(scope='usa',
                         showlakes = True,
                         lakecolor = 'rgb(85,173,240)')
             )
layout

and here is how I fire off the command:

choromap = go.Figure(data = [data],layout = layout)
iplot(choromap)

Any help, guidelines or pointers would be appreciated

1
I wish ;-) . No I get what you show, but the map is completely white (No data). - Did you get that from my data?Tony Sherman
Yes, both with Jupyter and regular offline python/plotly.Maximilian Peters

1 Answers

2
votes

Here is a minified working example which will give you the desired output.

enter image description here

import pandas as pd
import io
import plotly.graph_objs as go 
from plotly.offline import plot

txt = """   state   abv ibu id  beer    style   ounces  brewery city
0   AK  25  17  25  25.0    25.0    25  25  25
1   AL  10  9   10  10.0    10.0    10  10  10
2   AR  5   1   5   5.0 5.0 5   5   5
3   AZ  44  24  47  47.0    46.0    47  47  47
4   CA  182 135 183 183.0   183.0   183 183 183
5   CO  250 146 265 265.0   263.0   265 265 265
6   CT  27  6   27  27.0    27.0    27  27  27
7   DC  8   4   8   8.0 8.0 8   8   8
8   DE  1   1   2   2.0 2.0 2   2   2
9   FL  56  37  58  58.0    58.0    58  58  58
10  GA  16  7   16  16.0    16.0    16  16  16
"""

gb_state = pd.read_csv(io.StringIO(txt), delim_whitespace=True)


data = dict(type='choropleth',
            locations=gb_state['state'],
            locationmode='USA-states',
            text=gb_state['state'],
            z=gb_state['beer'],
            ) 

layout = dict(geo = dict(scope='usa',
                         showlakes= False)
             )

choromap = go.Figure(data=[data], layout=layout)
plot(choromap)