plotly python map subplot

时间:2018-03-05 09:19:15

标签: python plotly

我有以下工作代码,

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
"""

txt2 = """   state   abv ibu id  beer    style   ounces  brewery city
0   AK  25  17  25  30.0    25.0    25  25  25
1   AL  10  9   10  45.0    10.0    10  10  10
2   AR  5   1   5   100.0 5.0 5   5   5
3   AZ  44  24  47  150.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  800.0    27.0    27  27  27
7   DC  8   4   8   8.0 8.0 8   8   8
8   DE  1   1   2   1000.0 2.0 2   2   2
9   FL  56  37  58  5000.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)
gb_state1 = pd.read_csv(io.StringIO(txt2), delim_whitespace=True)

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

data2 = dict(type='choropleth',
            locations=gb_state1['state'],
            locationmode='USA-states',
            text=gb_state1['state'],
            z=gb_state1['beer'],
             geo = 'geo1'
            ) 

layout = dict()

layout['geo'] = dict(
        scope = 'usa',
        showland = True,
        landcolor = 'rgb(229, 229, 229)',
        showcountries = False,
        domain = dict( x = [0.0, 0.5], y = [0.0, 1.0] ),
        subunitcolor = "rgb(255, 255, 255)",
    )

layout['geo1'] = dict(
        scope = 'usa',
        showland = True,
        landcolor = 'rgb(229, 229, 229)',
        showcountries = False,
        domain = dict( x = [0.5, 1.0], y = [0.0, 1.0] ),
        subunitcolor = "rgb(255, 255, 255)",
    )

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

我正在尝试使用plotly生成地图的子图。为此,我添加了两个跟踪和两个域。

domain1 = dict( x = [0.0, 0.5], y = [0.0, 1.0] ), domain2 = dict( x = [0.5, 1.0], y = [0.0, 1.0] ),

我正在尝试连续打印两个地理图表。意思是1行和2列。当我执行上面的代码时,我只得到一个图。

任何人都可以发牢骚 - 代码出了什么问题?如何使用plotly绘制多个地图?

0 个答案:

没有答案