[英]Scattergeo of Canada using plotly in python
I would like to visualize the strategy of Canadian stores on plotly map. 我想在情节地图上想象加拿大商店的策略。 I have done this for American stores. 我为美国商店做过这件事。 I just want to replicate it for Canada. 我只是想为加拿大复制它。 I think location mode
, scope
and projection
should change, but I do not know with which value. 我认为location mode
, scope
和projection
应该改变,但我不知道具有哪个值。 I would appreciate any help. 我将不胜感激任何帮助。
def visualize_geo_store_canada(stores_info_df,
fig_name='store_strategy_Canada_map', title = 'Stores Strategy'):
data = [ dict(
type = 'scattergeo',
##### WHAT TO REPLACE? ########
#locationmode = 'USA-states',
###############################
lon = stores_info_df['LONGITUDE'],
lat = stores_info_df['LATITUDE'],
text = stores_info_df['STRATEGY'],
mode = 'markers',
marker = dict(
colorscale= 'Jet',
color = stores_info_df['STRATEGY'],
colorbar = dict(
title = 'Strategy',
titleside = 'top',
tickmode = 'array',
)
))]
layout = dict(
title = title,
geo = dict(
##### WHAT TO REPLACE? ########
#scope='usa',
#projection=dict( type='albers usa' ),
###############################
showland = True,
landcolor = "rgb(250, 250, 250)",
subunitcolor = "rgb(217, 217, 217)",
countrycolor = "rgb(217, 217, 217)",
countrywidth = 0.5,
subunitwidth = 0.5
),
)
fig = dict(data=data, layout=layout)
plotly.offline.iplot(fig, validate=False)
You need to specify to additional parameters lataxis
and lonaxis
in geo
dictionary in layout
(based on this ). 您需要在layout
中的geo
字典中指定其他参数lataxis
和lonaxis
(基于此 )。 Such parameters such locationmode
and scope
not helped for me in that case. 在这种情况下,这样的locationmode
和scope
等参数对我没有帮助。
Code: 码:
# import all the necessaries libraries
from plotly import tools
import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd
# your df
stores_info_df = pd.DataFrame({'LONGITUDE':[-60,-80,-100,-120],
'LATITUDE':[50,51,53,54],
'STRATEGY':['One','Two','Three','Four']})
# your function
def visualize_geo_store_canada(stores_info_df,
fig_name='store_strategy_Canada_map', title = 'Stores Strategy'):
data = [ dict(
type = 'scattergeo',
##### WHAT TO REPLACE? ########
#locationmode = 'Canada',
###############################
lon = stores_info_df['LONGITUDE'],
lat = stores_info_df['LATITUDE'],
text = stores_info_df['STRATEGY'],
mode = 'markers',
marker = dict(
colorscale= 'Jet',
color = stores_info_df['STRATEGY'],
colorbar = dict(
title = 'Strategy',
titleside = 'top',
tickmode = 'array',
)
))]
layout = dict(
title = title,
geo = dict(
##### WHAT TO REPLACE? ########
#scope='north-america',
###############################
showland = True,
# Add coordinates limits on a map
lataxis = dict(range=[40,70]),
lonaxis = dict(range=[-130,-55]),
landcolor = "rgb(250, 250, 250)",
subunitcolor = "rgb(217, 217, 217)",
countrycolor = "rgb(217, 217, 217)",
countrywidth = 0.5,
subunitwidth = 0.5
),
)
fig = dict(data=data, layout=layout)
py.plot(fig, validate=False)
# plot a plot
visualize_geo_store_canada(stores_info_df)
Output: 输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.