Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add label on choropleth map python

mapboxtoken="****"
mapboxstyle="mapbox://styles/***"
Comment

add label on choropleth map python

import plotly.express as px
import plotly.graph_objects as go
import geopandas as gpd

df = px.data.election()
geojson = px.data.election_geojson()
gdf = (
    gpd.GeoDataFrame.from_features(geojson)
    .merge(df, on="district")
    .assign(lat=lambda d: d.geometry.centroid.y, lon=lambda d: d.geometry.centroid.x)
    .set_index("district", drop=False)
)

# for convenience of rebuilding and adding traces...
def basemap():
    fig = px.choropleth_mapbox(
        df,
        geojson=geojson,
        color="Bergeron",
        locations="district",
        featureidkey="properties.district",
        center={"lat": 45.5517, "lon": -73.7073},
        mapbox_style=mapboxstyle,
#         mapbox_style="carto-positron",
        zoom=9,
    )
    fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0},
                      mapbox={"accesstoken":mapboxtoken}
                     )
    return fig
Comment

add label on choropleth map python

#!usr/bin/python
# encoding=utf8

import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )


import plotly.plotly as py
import pandas as pd

df = pd.read_csv('G20 data.csv')

data = [ dict(
        type = 'choropleth',
        locations = df['code'],
        z = df['article_number'],
        text = df['name'],
        #colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],[0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
        colorscale=[[0,'#0018ad'],[0.2,'#0222e3'],[0.4,'#3f5afd'],[0.6,'#7083fb'],[0.8,'#90a0fd'],[1,'#a3b0ff']],
        autocolorscale = False,
        reversescale = True,
        marker = dict(
            line = dict (
                color = 'rgb(180,180,180)',
                width = 0.5
            ) ),
        colorbar = dict(
            autotick = False,
            tickprefix = '',
            title = 'number of articles'),
      ) ]

layout = dict(
    title = "G20 countries' scientific articles"
    geo = dict(
        showframe = False,
        showcoastlines = False,
        showlocations=True,
        showland=True,
        landcolor='#f0f0f0',
        projection = dict(type = 'Mercator')
    )
)

fig = dict( data=data, layout=layout )
py.plot( fig, validate=False, filename='d3-world-map-2')
Comment

PREVIOUS NEXT
Code Example
Python :: pandas read float numbers with coma 
Python :: python class private variables 
Python :: 10.4.1.3. return Terminates Function Execution 
Python :: type operator in python 
Python :: pade python 
Python :: hmac decrypt python 
Python :: how to replace zero with null in python 
Python :: what is certifi module in python 
Python :: pyjone location 
Python :: mhaan meaning in english 
Python :: python - concatenate if null 
Python :: pandas show head and tail 
Python :: np.argmax python could not be evaluated 
Python :: python: dunder init method 
Python :: py3 dict values 
Python :: python hash md5 unicode 
Python :: pandas isolate data lower than a certain percentage 
Python :: Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : EOF within quoted string 
Python :: fibonacci sequence script python 
Python :: KivyMD video recording 
Python :: activate inherit function django 
Python :: how to make a square multicolor square spiral python 
Python :: priting matrix using np truncating the output 
Python :: numpy transpose shorthand 
Python :: sort dictionary by values 
Python :: get all non numeric columns pandas 
Python :: get the least value from a list of dictionaries 
Python :: fill variable based on values of other variables python 
Python :: load shapefile fiona multiline intersection 
Python :: pyttsx3 Using an external event loop¶ 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =