I try to create a visualization about the 'Number Of Cafes Within A 200 M Radius Of The Transjakarta Route' using OSMNX. I do my work here.
But I have some questions here:
Thank you.
I try to create a visualization about the 'Number Of Cafes Within A 200 M Radius Of The Transjakarta Route' using OSMNX. I do my work here.
But I have some questions here:
Thank you.
I want to remove all the cafe's plots that are far away from Transjakarta's line. I just want to show the cafe that intersects with Transjakarta's line because the radius range is only 200m from Transjakarta's line. How can I do that?
You just need to intersect your cafes' points with a 200-meter buffer around your transit lines.
import osmnx as ox
# get the transit lines near some point
point = (34.05, -118.25)
tags = {"railway": ["light_rail", "subway"]}
gdf_rail = ox.features.features_from_point(point, tags, dist=1500)
bbox = gdf_rail.union_all().envelope
gdf_rail = ox.projection.project_gdf(gdf_rail)
# get the cafes within 200 meters of the transit lines
tags = {"amenity": "cafe"}
gdf_poi = ox.features.features_from_polygon(bbox, tags).to_crs(gdf_rail.crs)
gdf_poi = gdf_poi[gdf_poi.intersects(gdf_rail.union_all().buffer(200))]
gdf_poi.shape
# plot the transit lines and nearby cafes
ax = gdf_rail.plot()
ax = gdf_poi.plot(ax=ax)
How can I show the legend title?
Previously answered at Title for matplotlib legend