简体   繁体   中英

Plotly express shows Invalid property for latitude for choropleth map plot for python

I am using these dataset " dataset tempat perlancongan Malaysia.csv". In that I'm Passing the latitude and longitude for plotting the plot plot for spatial coordinate vs numerical feature.

error I got =

Value Error: Invalid property specified for object of type plotly.graph_objs.Choropleth: 'lat'

  • I don't speak Malay so can't fully find data set you partially reference. Have used this one pelancongan data
  • it's appears you have not understood what a choropleth is. A choropleth uses polygons as the geometry, not points. From fact you are trying to pass lat and the data I have found provided latitude and longitude your data supports a scatter not a choropleth
import requests, io
import plotly.express as px

# https://www.data.gov.my/data/en_US/dataset/lokasi-tempat-pelancongan-mengikut-daerah-di-negeri-selangor/resource/18b5c1e0-e362-41a2-935c-c35795df9d17
df = pd.read_csv(
    io.StringIO(
        requests.get(
            "https://www.data.gov.my/data/en_US/datastore/dump/18b5c1e0-e362-41a2-935c-c35795df9d17"
        ).text
    )
)

px.scatter_geo(df, lat="LATITUDE", lon="LONGITUDE", hover_data=["NAMA"]).update_layout(
    geo_scope="asia", geo_fitbounds="locations"
)

在此处输入图像描述

mapbox ***

px.scatter_mapbox(
    df,
    lat="LATITUDE",
    lon="LONGITUDE",
    hover_data=["NAMA"],
    mapbox_style="carto-positron",
)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM