Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何摆脱Choropleth的白色背景?_Python_Dictionary_Plotly - Fatal编程技术网

Python 如何摆脱Choropleth的白色背景?

Python 如何摆脱Choropleth的白色背景?,python,dictionary,plotly,Python,Dictionary,Plotly,我正在使用Potly dashboard构建一个仪表板。我使用了一个黑暗的引导主题,因此我不想要一个白色的背景 但是,我的地图现在看起来如下所示: 产生它的代码如下所示: trace_map = html.Div( [ dcc.Graph( id = "map", figure = go.Figure( data=go.Choropleth(

我正在使用Potly dashboard构建一个仪表板。我使用了一个黑暗的引导主题,因此我不想要一个白色的背景

但是,我的地图现在看起来如下所示:

产生它的代码如下所示:

trace_map = html.Div(
    [
        dcc.Graph(
            id = "map",
            figure = go.Figure(
                data=go.Choropleth(
                locations=code, # Spatial coordinates
                z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )
        )
    ]
)
我试过
paper\u bgcolor
,也试过
plot\u bgcolor
,但没能成功

理想情况下,我希望实现此图像的外观(请忽略红点): 一般来说:

fig.update_layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'))
在你的具体例子中:

go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)')
绘图:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
你可能也想改变湖泊的颜色。但是请注意,设置
lakecolor='rgba(0,0,0,0)
将使湖泊的颜色与各州相同,而不是地面。所以我选择了湖色=“#4E5D6C”。当然,您可以对
bgcolor
执行相同的操作,但是将其设置为
'rgba(0,0,0,0)
可以去除您特别要求的白色

湖泊颜色图:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

湖泊颜色代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
我们也可以改变州边界的颜色,或者在这个上下文中更隐晦地称为
subkecolor
。为了更好地匹配您想要的最终结果,我们还可以为landcolor添加香料:

州边界和州颜色,打印:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

州边界和州颜色,代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
一般来说:

fig.update_layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'))
在你的具体例子中:

go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)')
绘图:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
你可能也想改变湖泊的颜色。但是请注意,设置
lakecolor='rgba(0,0,0,0)
将使湖泊的颜色与各州相同,而不是地面。所以我选择了湖色=“#4E5D6C”。当然,您可以对
bgcolor
执行相同的操作,但是将其设置为
'rgba(0,0,0,0)
可以去除您特别要求的白色

湖泊颜色图:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

湖泊颜色代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
我们也可以改变州边界的颜色,或者在这个上下文中更隐晦地称为
subkecolor
。为了更好地匹配您想要的最终结果,我们还可以为landcolor添加香料:

州边界和州颜色,打印:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

州边界和州颜色,代码:

import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()
import plotly.graph_objects as go

fig  = go.Figure(
                data=go.Choropleth(
                #locations=code, # Spatial coordinates
                #z = df.groupby(['month']).sum()['Sales'].astype(int), 
                locationmode = 'USA-states',
                colorscale = 'Reds',
                colorbar_title = "USD",
            ), layout = go.Layout(geo=dict(bgcolor= 'rgba(0,0,0,0)', lakecolor='#4E5D6C',
                                          landcolor='rgba(51,17,0,0.2)',
                                          subunitcolor='grey'),
                                  title = 'The Cities Sold the Most Product',
                                  font = {"size": 9, "color":"White"},
                                  titlefont = {"size": 15, "color":"White"},
                                  geo_scope='usa',
                                  margin={"r":0,"t":40,"l":0,"b":0},
                                  paper_bgcolor='#4E5D6C',
                                  plot_bgcolor='#4E5D6C',
                                  )
            )

fig.show()

我在这里找到了自己的路,因为我想改变我的Choroplethmapbox的主题。接受的解决方案有所帮助,但最终我发现以下代码适用于我的情况:

实例化图形 添加一些痕迹 最后,使用更新布局更改主题
我在这里找到了自己的路,因为我想改变我的Choroplethmapbox的主题。接受的解决方案有所帮助,但最终我发现以下代码适用于我的情况:

实例化图形 添加一些痕迹 最后,使用更新布局更改主题
伟大的谢谢,但是我不知道我应该把这个片段放在哪里。请告诉我好吗?因为我试着把geo放进go.Layout,但它显示了错误。@yts61我自己没有太多使用过
dcc.Graph
。但是如果你把
geo=dict(bgcolor='rgba(0,0,0,0)
放入你的
go.Layout
定义中,它应该可以正常工作。这对我来说很有效。谢谢,太好了!谢谢,但是我不知道我应该把这个片段放在哪里。请告诉我好吗?因为我试着把geo放进go.Layout,但它显示了错误。@yts61我自己没有太多使用过
dcc.Graph
。但是如果你把
geo=dict(bgcolor='rgba(0,0,0,0)
放入你的
go.Layout
定义中,它应该可以正常工作。这对我来说很有效。谢谢