Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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-plotly-组合气泡和choropleth贴图_Python_Dictionary_Plotly - Fatal编程技术网

Python-plotly-组合气泡和choropleth贴图

Python-plotly-组合气泡和choropleth贴图,python,dictionary,plotly,Python,Dictionary,Plotly,在对这个问题的回答中,很好地描述了如何在一张地图中绘出气泡贴图和choropleth贴图。我想在Python中复制完全相同的示例,但是我没有根据plotly文档()中提供的信息进行管理 等效R代码如下所示: lon = c(-73.9865812, -118.2427266, -87.6244212, -95.3676974) pop = c(8287238, 3826423, 2705627, 2129784) df_cities = data.frame(cities, lat, lon,

在对这个问题的回答中,很好地描述了如何在一张地图中绘出气泡贴图和choropleth贴图。我想在Python中复制完全相同的示例,但是我没有根据plotly文档()中提供的信息进行管理

等效R代码如下所示:

lon = c(-73.9865812, -118.2427266, -87.6244212, -95.3676974)
pop = c(8287238, 3826423, 2705627, 2129784)
df_cities = data.frame(cities, lat, lon, pop)

state_codes = c("NY", "CA", "IL", "TX")
pop = c(19746227.0, 38802500.0, 12880580.0, 26956958.0)
df_states = data.frame(state_codes, pop)

plot_ly(df_cities, lon=lon, lat=lat, 
        text=paste0(df_cities$cities,'<br>Population: ', df_cities$pop), 
        marker= list(size = sqrt(pop/10000) + 1), type="scattergeo",
        filename="stackoverflow/choropleth+scattergeo") %>%
  add_trace(z=df_states$pop,
            locations=df_states$state_codes, 
            text=paste0(df_states$state_codes, '<br>Population: ', df_states$pop),
            type="choropleth", 
            colors = 'Purples', 
            locationmode="USA-states") %>%
  layout(geo = list(scope="usa"))
lon=c(-73.9865812,-118.2427266,-87.6244212,-95.3676974)
pop=c(8287238382642327056272129784)
df_cities=data.frame(cities、lat、lon、pop)
州代码=c(“纽约”、“加州”、“伊利诺伊州”、“德克萨斯州”)
pop=c(19746227.0、38802500.0、12880580.0、26956958.0)
df_states=data.frame(状态代码,pop)
地块(df_城市,lon=lon,lat=lat,
text=paste0(df_cities$cities,
人口:',df_cities$pop), marker=list(大小=sqrt(pop/10000)+1),type=“scattergeo”, filename=“stackoverflow/choropleth+scattergeo”)%>% 添加_跟踪(z=df_状态$pop, 位置=df_状态$状态代码, text=paste0(df_states$state_代码,
填充:',df_states$pop), type=“choropleth”, 颜色=‘紫色’, locationmode=“美国州”)%>% 布局(地理=列表(scope=“usa”))

如何在Python中实现这一点?

只需将
.py
附加到图形的URL(例如)即可查看相应的Python代码。

我发现我必须稍微调整代码以使其正常工作:

cities = c('New York', 'Los Angeles', 'Chicago', 'Houston')
lat = c(40.7305991, 34.053717, 41.8755546, 29.7589382)
lon = c(-73.9865812, -118.2427266, -87.6244212, -95.3676974)
pop = c(8287238, 3826423, 2705627, 2129784)
df_cities = data.frame(cities, lat, lon, pop)

state_codes = c("NY", "CA", "IL", "TX")
pop = c(19746227.0, 38802500.0, 12880580.0, 26956958.0)
df_states = data.frame(state_codes, pop)

plot_ly(df_cities, lon=lon, lat=lat,
         text = paste0(df_cities$cities,'<br>Population: ', df_cities$pop),
         marker = list(size = sqrt(pop/10000) + 1), type="scattergeo",
         filename = "stackoverflow/choropleth+scattergeo") %>%
 add_trace(z=df_states$pop,
    locations = df_states$state_codes,
    text = paste0(df_states$state_codes, '<br>Population: ', df_states$pop),
    type = "choropleth",
    colors = 'Purples',
    locationmode = "USA-states") %>%
 layout(geo = list(scope="usa"))
cities=c('纽约'、'洛杉矶'、'芝加哥'、'休斯顿')
纬度=c(40.7305991,34.053717,41.8755546,29.7589382)
lon=c(-73.9865812,-118.2427266,-87.6244212,-95.3676974)
pop=c(8287238382642327056272129784)
df_cities=data.frame(cities、lat、lon、pop)
州代码=c(“纽约”、“加州”、“伊利诺伊州”、“德克萨斯州”)
pop=c(19746227.0、38802500.0、12880580.0、26956958.0)
df_states=data.frame(状态代码,pop)
地块(df_城市,lon=lon,lat=lat,
text=paste0(df_cities$cities,
人口:',df_cities$pop), marker=list(大小=sqrt(pop/10000)+1),type=“scattergeo”, filename=“stackoverflow/choropleth+scattergeo”)%>% 添加_跟踪(z=df_状态$pop, 位置=df_状态$状态代码, text=paste0(df_states$state_代码,
填充:',df_states$pop), type=“choropleth”, 颜色=‘紫色’, locationmode=“美国州”)%>% 布局(地理=列表(scope=“usa”))
这不是像问题所要求的那样的python答案