更改颜色=时,Plotly Choropleth地图被卡住了。

发布于 2025-02-01 01:26:01 字数 1131 浏览 3 评论 0原文

我正在尝试使用预测的自闭症患病率创建英国地方当局的情节合唱。当我尝试分配“ color = predictionprevalence”时,脚本就会被无限加载,以便脉络脉络显示每个权威区域中数据集的自闭症率。我不确定我需要做什么。 我附上了脚本挂在哪里

import pandas as pd
import json
from urllib.request import urlopen
import numpy as np
#With Plotly
import plotly.express as px
from geojson_rewind import rewind

with urlopen('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json') as response:
    counties = json.load(response)

df=pd.read_csv('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json')

counties_corrected=rewind(counties,rfc7946=False)

fig = px.choropleth(df, geojson=counties_corrected, locations='nuts318cd', featureidkey="properties.nuts318cd", color='predictedprevalence',
                            color_continuous_scale="PurPor", labels={'label name':'label name'}, title='MAP TITLE',
                            scope="europe")

fig.update_geos(fitbounds="locations", visible=False)

图像(lauth2020.csv)看起来像。有311个条目:

dataset

我已经与此相处几天了非常感谢一些帮助。 谢谢

I am trying to create a plotly choropleth map of the uk local authorities, using predicted autism prevalence. The script is getting stuck infinitely loading when I try and assign "colour=predictedprevalence" so that the choropleth shows predicted autism rates from the dataset in each authority area. I am unsure what I need to do.
I have attached an image of where the script hangs shows where the script hangs

import pandas as pd
import json
from urllib.request import urlopen
import numpy as np
#With Plotly
import plotly.express as px
from geojson_rewind import rewind

with urlopen('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json') as response:
    counties = json.load(response)

df=pd.read_csv('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json')

counties_corrected=rewind(counties,rfc7946=False)

fig = px.choropleth(df, geojson=counties_corrected, locations='nuts318cd', featureidkey="properties.nuts318cd", color='predictedprevalence',
                            color_continuous_scale="PurPor", labels={'label name':'label name'}, title='MAP TITLE',
                            scope="europe")

fig.update_geos(fitbounds="locations", visible=False)

This is what my dataset (lauth2020.csv) looks like. There are 311 entries:

dataset

I have been a wee stuck for a few days with this and would really appreciate some assistance.
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

才能让你更想念 2025-02-08 01:26:01

您是否确定不会错误地指定用户数据,它应该以CSV格式指定,但是您正在阅读JSON格式。我数据登录了您的CSV数据图像并运行了代码。该图似乎正确显示。

import pandas as pd
import json
from urllib.request import urlopen
import numpy as np
#With Plotly
import plotly.express as px
from geojson_rewind import rewind

with urlopen('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json') as response:
    counties = json.load(response)

counties_corrected=rewind(counties,rfc7946=False)

import io

data = '''
nuts318cd "local authority" year predictedprevalence latitude longitude
UKC11 Adur 2020 357 50.84572 -0.32417 
UKC12 Allerdale 2020 551 54.68524 -3.2809
UKC13 "Amber Valley" 2020 746 53.02884 -1.46219
UKC14 Arun 2020 845 50.84321 -0.64999
UKC21 Ashfield 2020 761 53.09747 -1.25422
UKC22 Ashford 2020 742 51.13096 0.823374
UKC23 Babergh 2020 496 52.0645 0.916149 
UKD11 "Barking and Dagenham" 2020 1307 51.54555 0.129479
UKD12 Barnet 2020 2476 51.61107 -0.21819 
UKD33 Barnsley 2020 1470 53.52577 -1.54925 
UKD34 "Barrow-in-Furness" 2020 390 54.15731 -3.1999 
UKD35 Basildon 2020 1091 51.59036 0.475055 
UKD36 "Basingstoke and Deane" 2020 1055 51.25937 -1.22021 
UKD37 Bassetlaw 2020 686 53.35604 -0.9787 
UKD41 "Bath and North East Somerset" 2020 1226 51.35604 -2.48654
UKD42 Bedford 2020 1011 52.19628 -0.45463 
UKD44 Bexley 2020 1475 51.45822 0.146212 
UKD45 Birmingham 2020 7088 52.48404 -1.88141 
UKD46 Blaby 2020 595 52.57706 -1.19887 
UKD47 "Blackburn with Darwen" 2020 899 53.7008 -2.4636
UKD61 Blackpool 2020 821 53.82164 -3.02199 
UKD62 Bolsover 2020 485 53.23875 -1.27228 
UKD63 Bolton 2020 1682 53.58449 -2.47952 
UKD71 Boston 2020 419 52.97794 -0.11218 
UKD72 "Bournemouth, Christchurch and Poole" 2020 2381 50.74609 -1.84807
UKD73 "Bracknell Forest" 2020 755 51.4113 -0.73363 
UKD74 Bradford 2020 3145 53.84382 -1.87389 
UKE11 Braintree 2020 871 51.91634 0.575911 
UKE12 Breckland 2020 790 52.59421 0.818716 
UKE13 Brent 2020 2216 51.56438 -0.27568 
UKE21 Brentwood 2020 432 51.64108 0.290091 
UKE22 "Brighton and Hove" 2020 2070 50.8465 -0.15079 
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)

fig = px.choropleth(df, 
                    geojson=counties_corrected,
                    locations='nuts318cd',
                    featureidkey="properties.nuts318cd",
                    projection='mercator',
                    color='predictedprevalence',
                    color_continuous_scale="PurPor",
                    labels={'label name':'label name'},
                    title='MAP TITLE',
                    scope="europe"
                   )

fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(autosize=False,
                  width=800,
                  height=600,
                  margin={"r":0,"t":20,"l":0,"b":0})
fig.show()

Are you sure you are not specifying the user data incorrectly, it should be in csv format, but you are reading JSON format. I datamined your CSV data image and ran the code. The graph appears to be displayed correctly.

import pandas as pd
import json
from urllib.request import urlopen
import numpy as np
#With Plotly
import plotly.express as px
from geojson_rewind import rewind

with urlopen('https://raw.githubusercontent.com/plummy95/1312306/main/localauth.json') as response:
    counties = json.load(response)

counties_corrected=rewind(counties,rfc7946=False)

import io

data = '''
nuts318cd "local authority" year predictedprevalence latitude longitude
UKC11 Adur 2020 357 50.84572 -0.32417 
UKC12 Allerdale 2020 551 54.68524 -3.2809
UKC13 "Amber Valley" 2020 746 53.02884 -1.46219
UKC14 Arun 2020 845 50.84321 -0.64999
UKC21 Ashfield 2020 761 53.09747 -1.25422
UKC22 Ashford 2020 742 51.13096 0.823374
UKC23 Babergh 2020 496 52.0645 0.916149 
UKD11 "Barking and Dagenham" 2020 1307 51.54555 0.129479
UKD12 Barnet 2020 2476 51.61107 -0.21819 
UKD33 Barnsley 2020 1470 53.52577 -1.54925 
UKD34 "Barrow-in-Furness" 2020 390 54.15731 -3.1999 
UKD35 Basildon 2020 1091 51.59036 0.475055 
UKD36 "Basingstoke and Deane" 2020 1055 51.25937 -1.22021 
UKD37 Bassetlaw 2020 686 53.35604 -0.9787 
UKD41 "Bath and North East Somerset" 2020 1226 51.35604 -2.48654
UKD42 Bedford 2020 1011 52.19628 -0.45463 
UKD44 Bexley 2020 1475 51.45822 0.146212 
UKD45 Birmingham 2020 7088 52.48404 -1.88141 
UKD46 Blaby 2020 595 52.57706 -1.19887 
UKD47 "Blackburn with Darwen" 2020 899 53.7008 -2.4636
UKD61 Blackpool 2020 821 53.82164 -3.02199 
UKD62 Bolsover 2020 485 53.23875 -1.27228 
UKD63 Bolton 2020 1682 53.58449 -2.47952 
UKD71 Boston 2020 419 52.97794 -0.11218 
UKD72 "Bournemouth, Christchurch and Poole" 2020 2381 50.74609 -1.84807
UKD73 "Bracknell Forest" 2020 755 51.4113 -0.73363 
UKD74 Bradford 2020 3145 53.84382 -1.87389 
UKE11 Braintree 2020 871 51.91634 0.575911 
UKE12 Breckland 2020 790 52.59421 0.818716 
UKE13 Brent 2020 2216 51.56438 -0.27568 
UKE21 Brentwood 2020 432 51.64108 0.290091 
UKE22 "Brighton and Hove" 2020 2070 50.8465 -0.15079 
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)

fig = px.choropleth(df, 
                    geojson=counties_corrected,
                    locations='nuts318cd',
                    featureidkey="properties.nuts318cd",
                    projection='mercator',
                    color='predictedprevalence',
                    color_continuous_scale="PurPor",
                    labels={'label name':'label name'},
                    title='MAP TITLE',
                    scope="europe"
                   )

fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(autosize=False,
                  width=800,
                  height=600,
                  margin={"r":0,"t":20,"l":0,"b":0})
fig.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文