作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在 plotly map 上可视化加拿大商店的策略。我为美国商店做过这个。我只想为加拿大复制它。我认为location mode
、scope
和projection
应该改变,但我不知道哪个值。如果有任何帮助,我将不胜感激。
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)
最佳答案
您需要在 layout
的 geo
字典中指定附加参数 lataxis
和 lonaxis
(基于 this ).在这种情况下,locationmode
和 scope
等参数对我没有帮助。
代码:
# 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)
输出:
关于python - 加拿大的 Scattergeo 在 python 中使用 plotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54226468/
谁能帮我找出这里的错误吗? fig = go.Figure() fig.add_trace( go.Choroplethmapbox( geojson=counties,
我正在绘制一些类似于找到的第一个示例的数据 here (美国机 field 图)。但是,我没有绘制比例尺,而是绘制二元特征(假设一种颜色超过 15k 次飞行,一种颜色低于 15k 次飞行)。我看过文档
当我使用 plotly(在 python 中)时,我正在尝试使用离散色阶。我需要一个离散色标,因为我为特定城市绘制的某些值与所有其他城市相比太大了,因此离散色标可以帮助我轻松地可视化所有值。这是一个更
我想在 plotly map 上可视化加拿大商店的策略。我为美国商店做过这个。我只想为加拿大复制它。我认为location mode、scope和projection应该改变,但我不知道哪个值。如果有
我是一名优秀的程序员,十分优秀!