<jupyter_start><jupyter_text>[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/leafmap/blob/master/examples/notebooks/38_plotly.ipynb)[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)Uncomment the following line to install [leafmap](https://leafmap.org) if needed.<jupyter_code># !pip install leafmap
import leafmap.plotlymap as leafmap<jupyter_output><empty_output><jupyter_text>If you run into an error saying "FigureWidget - 'mapbox._derived' Value Error" ([source](https://github.com/plotly/plotly.py/issues/2570issuecomment-738735816)), uncomment the following line and run it.<jupyter_code># leafmap.fix_widget_error()<jupyter_output><empty_output><jupyter_text>Create an interactive map using default settings.<jupyter_code>m = leafmap.Map()
m<jupyter_output><empty_output><jupyter_text>Change default setting when creating a map.  Can be one of string from "open-street-map", "carto-positron", "carto-darkmatter", "stamen-terrain", "stamen-toner" or "stamen-watercolor" .<jupyter_code>m = leafmap.Map(center=(40, -100), zoom=3, basemap="stamen-terrain", height=500)
m<jupyter_output><empty_output><jupyter_text>Set map center and zoom level.<jupyter_code>m = leafmap.Map(basemap="stamen-watercolor")
m.set_center(lat=20, lon=0, zoom=2)
m<jupyter_output><empty_output><jupyter_text>Print out available basemaps.<jupyter_code>leafmap.basemaps.keys()<jupyter_output><empty_output><jupyter_text>Add a basemap.<jupyter_code>m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m<jupyter_output><empty_output><jupyter_text>Add XYZ tile layer.<jupyter_code>m = leafmap.Map()
tile_url = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}"
m.add_tile_layer(tile_url, name="Google Satellite", attribution="Google", opacity=1.0)
m<jupyter_output><empty_output><jupyter_text>Add a mapbox tile layer. You will need a mapbox token. The map style can be Can be "basic", "streets", "outdoors", "light", "dark", "satellite", or "satellite-streets".<jupyter_code>import os
# os.environ["MAPBOX_TOKEN"] = "<PASSWORD>-mapbox-token"
m = leafmap.Map()
m.add_mapbox_layer(style="streets")
m<jupyter_output><empty_output><jupyter_text>Remove the modebar in the upper-right corner.<jupyter_code>m = leafmap.Map(basemap="stamen-toner")
m
m.clear_controls()<jupyter_output><empty_output><jupyter_text>Add more buttons to the modebar.<jupyter_code>m = leafmap.Map(basemap="carto-positron")
controls = [
    'drawline',
    'drawopenpath',
    'drawclosedpath',
    'drawcircle',
    'drawrect',
    'eraseshape',
]
m.add_controls(controls)
m<jupyter_output><empty_output><jupyter_text>Add Cloud Optimized GeoTIFF.<jupyter_code>m = leafmap.Map()
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
m.add_cog_layer(url, name="Fire (pre-event)")
m<jupyter_output><empty_output><jupyter_text>Add a STAC item via HTTP URL.<jupyter_code>m = leafmap.Map()
url = 'https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json'
m.add_stac_layer(url, bands=['B3', 'B2', 'B1'], name='False color')
m<jupyter_output><empty_output><jupyter_text>Add a STAC item from Microsoft Planetary Computer.<jupyter_code>collection = "landsat-8-c2-l2"
item = "LC08_L2SP_047027_20201204_02_T1"
m = leafmap.Map()
m.add_stac_layer(
    collection=collection,
    item=item,
    bands=["SR_B7", "SR_B5", "SR_B4"],
    titiler_endpoint="pc",
)
m<jupyter_output><empty_output><jupyter_text>Add a heat map.<jupyter_code>url = 'https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv'
m = leafmap.Map(basemap="stamen-terrain")
m.add_heatmap(
    url, latitude="Latitude", longitude="Longitude", z="Magnitude", name="Earthquake"
)
m<jupyter_output><empty_output><jupyter_text>Add a choropleth map.<jupyter_code>url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
m = leafmap.Map(basemap="stamen-terrain")
m.add_choropleth_map(url, name="Pop", z="POP_EST", colorscale="Viridis")
m<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15190784737221022, 'fraction_numerical': 0.032157427405807536, 'mean_word_length': 7.849256900212314, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 66, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '28449', 'license': 'MIT', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1631, 'n_words': 225, 'path': 'docs/notebooks/38_plotly.ipynb', 'repo_name': 'glennlaughlin/leafmap', 'size': '4161'}