情节 choropleth 不绘制数据 [英] plotly choropleth not plotting data

查看:69
本文介绍了情节 choropleth 不绘制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的数据的链接

将pandas导入为pd导入 io导入 plotly.graph_objs as go从 plotly.offline 导入图txt = """ state abv ibu id 啤酒风格盎司啤酒城0 AK 25 17 25 25.0 25.0 25 25 251 AL 10 9 10 10.0 10.0 10 10 102 应收账款 5 1 5 5.0 5.0 5 5 53 AZ 44 24 47 47.0 46.0 47 47 474 CA 182 135 183 183.0 183.0 183 183 1835 二氧化碳 250 146 265 265.0 263.0 265 265 2656 CT 27 6 27 27.0 27.0 27 27 277 直流 8 4 8 8.0 8.0 8 8 88 DE 1 1 2 2.0 2.0 2 2 29 佛罗里达州 56 37 58 58.0 58.0 58 58 5810 GA 16 7 16 16.0 16.0 16 16 16"""gb_state = pd.read_csv(io.StringIO(txt), delim_whitespace=True)数据 = dict(type='choropleth',location=gb_state['state'],locationmode='USA-states',text=gb_state['state'],z=gb_state['啤酒'],)布局 = dict(geo = dict(scope='usa',秀湖=假))choromap = go.Figure(数据=[数据],布局=布局)情节(色差图)

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

解决方案

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

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)

这篇关于情节 choropleth 不绘制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆