36 add labels
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import leafmap
import leafmap
Update the package if needed.
In [3]:
Copied!
# leafmap.update_package()
# leafmap.update_package()
Create an interactive map.
In [4]:
Copied!
data = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us-states.json"
data = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us-states.json"
In [5]:
Copied!
Map = leafmap.Map(center=[40, -100], zoom=4, add_google_map=False, layers_control=True)
Map = leafmap.Map(center=[40, -100], zoom=4, add_google_map=False, layers_control=True)
Labeling data.
In [6]:
Copied!
Map.add_labels(
data,
"id",
font_size="12pt",
font_color="blue",
font_family="arial",
font_weight="bold",
)
Map
Map.add_labels(
data,
"id",
font_size="12pt",
font_color="blue",
font_family="arial",
font_weight="bold",
)
Map
--------------------------------------------------------------------------- HTTPError Traceback (most recent call last) Input In [6], in <cell line: 1>() ----> 1 Map.add_labels( 2 data, 3 "id", 4 font_size="12pt", 5 font_color="blue", 6 font_family="arial", 7 font_weight="bold", 8 ) 9 Map File ~/.local/lib/python3.9/site-packages/leafmap/foliumap.py:1807, in Map.add_labels(self, data, column, font_size, font_color, font_family, font_weight, x, y, draggable, layer_name, **kwargs) 1804 try: 1805 import geopandas as gpd -> 1807 df = gpd.read_file(data) 1808 df[x] = df.centroid.x 1809 df[y] = df.centroid.y File ~/.local/lib/python3.9/site-packages/geopandas/io/file.py:170, in _read_file(filename, bbox, mask, rows, **kwargs) 167 filename = _expand_user(filename) 169 if _is_url(filename): --> 170 req = _urlopen(filename) 171 path_or_bytes = req.read() 172 reader = fiona.BytesCollection File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:214, in urlopen(url, data, timeout, cafile, capath, cadefault, context) 212 else: 213 opener = _opener --> 214 return opener.open(url, data, timeout) File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:523, in OpenerDirector.open(self, fullurl, data, timeout) 521 for processor in self.process_response.get(protocol, []): 522 meth = getattr(processor, meth_name) --> 523 response = meth(req, response) 525 return response File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:632, in HTTPErrorProcessor.http_response(self, request, response) 629 # According to RFC 2616, "2xx" code indicates that the client's 630 # request was successfully received, understood, and accepted. 631 if not (200 <= code < 300): --> 632 response = self.parent.error( 633 'http', request, response, code, msg, hdrs) 635 return response File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:561, in OpenerDirector.error(self, proto, *args) 559 if http_err: 560 args = (dict, 'default', 'http_error_default') + orig_args --> 561 return self._call_chain(*args) File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 492 for handler in handlers: 493 func = getattr(handler, meth_name) --> 494 result = func(*args) 495 if result is not None: 496 return result File /opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/urllib/request.py:641, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs) 640 def http_error_default(self, req, fp, code, msg, hdrs): --> 641 raise HTTPError(req.full_url, code, msg, hdrs, fp) HTTPError: HTTP Error 404: Not Found
Remove labels
In [7]:
Copied!
Map.remove_labels()
Map.remove_labels()
The folium plotting backend does not support removing labels.
Last update:
2022-03-14