Code used:

import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
import geopandas as gpd
import pandas as pd

Place_name = "Trafaria, Portugal"
area = ox.geocode_to_gdf(Place_name)

tags_substation = {'power': 'substation'}
substation = ox.geometries_from_place(Place_name, tags_substation)
print("Retrieved", len(substation), "substation objects")

tags_power_tower = {'power': 'tower'}
power_tower = ox.geometries_from_place(Place_name, tags_power_tower)
print("Retrieved", len(power_tower), "power_tower objects")

tags_power_line = {'power': 'line'}
power_line = ox.geometries_from_place(Place_name, tags_power_line)
print("Retrieved", len(power_line), "power_line objects")
power_line_inside_area = gpd.clip(power_line,area)

buildings = ox.geometries_from_place(Place_name, {"building": True})

fig, ax = plt.subplots(figsize = (12,8))
area.plot(ax=ax, facecolor = "black")
substation.plot(ax=ax, facecolor = "red", alpha = 1)
power_tower.plot(ax=ax, facecolor = "blue", alpha = 1, markersize = 15)
power_line_inside_area.plot(ax=ax, linewidth=1, edgecolor="crimson")
buildings.plot(ax=ax, facecolor="silver", alpha=0.3)

This is one of the plots i get:

enter image description here

I want to have labels saying for example that grey is for buildings, blue is for substations, magenta for power lines and so on.

How can i do that?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.