如何在布局图的下拉菜单中更改chorpleth贴图的图层?

时间:2019-08-07 09:31:25

标签: python-3.x plotly

我遵循了本教程: https://plot.ly/~empet/14692/mapbox-choropleth-that-works-with-plotly/#/

我在地图上添加了一个下拉菜单,以便在不同的列之间动态选择。在示例中是一个特定列表,其中列出了每种形状的颜色。我的问题是:

如何动态更改布局各层的颜色?我可以将带有数据的字典传递给无花果元素,但是布局是不可能的。

我试图在列表中存储不同的图层:

Uncaught Error: Template parse errors:
Can't bind to 'active' since it isn't a known property of 'a'. (" col-md-3 px-0">
            <a class="nav-link active show m-0" data-toggle="tab" href="#toDoTab" [ERROR ->][active]="tab && tab === 0" role="tablist">
              <i class="fas fa-tasks"></i>
            "): ng:///AppModule/ProjectListComponent.html@22:82
Can't bind to 'active' since it isn't a known property of 'a'. ("av-item col-md-3 px-0">
            <a class="nav-link m-0" data-toggle="tab" href="#followUpTab"  [ERROR ->][active]="tab && tab === 0" role="tablist">
              <i class="far fa-list-alt"></i>
         "): ng:///AppModule/ProjectListComponent.html@28:75
    at syntaxError (compiler.js:2409)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:11976)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:27248)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:27235)
    at compiler.js:27178
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:27178)
    at compiler.js:27088
    at Object.then (compiler.js:2400)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:27087)

但是数据正确更改,但图层不会更改:

layers=[dict(sourcetype = 'geojson',
             source =sources[k],
             #below="water", 
             type = 'fill',   
             color = facecolor[k],
             opacity=0.8
            ) for k in range(len(sources))]

layers2 = [dict(sourcetype = 'geojson',
             source =sources[k],
             #below="water", 
             type = 'fill',   
             color = facecolor_spd[k],
             opacity=0.8
            ) for k in range(len(sources))]

lay_list = [layers,layers2]

for s in range(0,len(party_list)):
    visible_traces = [False] * total_codes
    visible_traces[s + 1] = True
    updatemenus[0]['buttons'].append(dict(args=[{'visible': vis_list[s]}],
                                          label=party_list[s],
                               layout=dict(mapbox=dict(layers=lay_list[s])),
                                          method='update'))

但是,在此示例中,数据来自“ SPD”,但该层仍然是 数据[0]层:

https://i.imgur.com/E51FmDY.png

任何有关如何动态更改图层的帮助都很好。

0 个答案:

没有答案