Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Visualizing Maps with GeoPandas | Visualization and Applied Geospatial Analysis
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Geospatial Data Science with Python

bookVisualizing Maps with GeoPandas

Visualizing geospatial data is a fundamental skill in geospatial data science, enabling you to explore spatial patterns, communicate results, and make informed decisions. With GeoPandas, you can quickly create maps from your spatial datasets and customize their appearance using the powerful plotting capabilities of matplotlib. GeoPandas integrates seamlessly with matplotlib, allowing you to plot points, lines, and polygons directly from a GeoDataFrame. By adjusting colors, edge styles, and overlays, you can highlight important features and make your maps more informative and visually appealing.

1234567891011121314151617181920212223
import geopandas as gpd import matplotlib.pyplot as plt from shapely.geometry import Polygon # Create a GeoDataFrame with polygon geometries polygons = [ Polygon([(0, 0), (2, 0), (2, 2), (0, 2)]), Polygon([(2, 0), (4, 0), (4, 2), (2, 2)]), Polygon([(0, 2), (2, 2), (2, 4), (0, 4)]), ] gdf = gpd.GeoDataFrame({'geometry': polygons, 'name': ['A', 'B', 'C']}) # Plot polygons with custom face colors and edge styles ax = gdf.plot( color=['lightblue', 'lightgreen', 'orange'], edgecolor='black', linewidth=2, linestyle='--' ) plt.title("Custom Polygon Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.show()
copy
123456789101112131415161718192021222324252627282930313233
import geopandas as gpd import matplotlib.pyplot as plt from shapely.geometry import Polygon, Point # Create polygon GeoDataFrame polygons = [ Polygon([(0, 0), (5, 0), (5, 5), (0, 5)]), ] gdf_polygons = gpd.GeoDataFrame({'geometry': polygons}) # Create points GeoDataFrame points = [ Point(1, 1), Point(3, 4), Point(4, 2), ] gdf_points = gpd.GeoDataFrame({'geometry': points, 'label': ['School', 'Hospital', 'Shop']}) # Plot polygons ax = gdf_polygons.plot(color='lightyellow', edgecolor='black', figsize=(6, 6)) # Overlay points gdf_points.plot(ax=ax, color='red', marker='o', markersize=80, label='Locations of Interest') # Annotate points for x, y, label in zip(gdf_points.geometry.x, gdf_points.geometry.y, gdf_points['label']): plt.text(x + 0.1, y, label, fontsize=10) plt.title("Locations of Interest Overlayed on Polygon Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.legend() plt.show()
copy

1. Which library does GeoPandas use for plotting maps?

2. How can you change the color of features in a GeoPandas plot?

question mark

Which library does GeoPandas use for plotting maps?

Select the correct answer

question mark

How can you change the color of features in a GeoPandas plot?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 1

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

How can I customize the appearance of the polygons or points further?

Can I add more types of geometries, like lines, to the map?

How do I save the generated map as an image file?

bookVisualizing Maps with GeoPandas

Glissez pour afficher le menu

Visualizing geospatial data is a fundamental skill in geospatial data science, enabling you to explore spatial patterns, communicate results, and make informed decisions. With GeoPandas, you can quickly create maps from your spatial datasets and customize their appearance using the powerful plotting capabilities of matplotlib. GeoPandas integrates seamlessly with matplotlib, allowing you to plot points, lines, and polygons directly from a GeoDataFrame. By adjusting colors, edge styles, and overlays, you can highlight important features and make your maps more informative and visually appealing.

1234567891011121314151617181920212223
import geopandas as gpd import matplotlib.pyplot as plt from shapely.geometry import Polygon # Create a GeoDataFrame with polygon geometries polygons = [ Polygon([(0, 0), (2, 0), (2, 2), (0, 2)]), Polygon([(2, 0), (4, 0), (4, 2), (2, 2)]), Polygon([(0, 2), (2, 2), (2, 4), (0, 4)]), ] gdf = gpd.GeoDataFrame({'geometry': polygons, 'name': ['A', 'B', 'C']}) # Plot polygons with custom face colors and edge styles ax = gdf.plot( color=['lightblue', 'lightgreen', 'orange'], edgecolor='black', linewidth=2, linestyle='--' ) plt.title("Custom Polygon Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.show()
copy
123456789101112131415161718192021222324252627282930313233
import geopandas as gpd import matplotlib.pyplot as plt from shapely.geometry import Polygon, Point # Create polygon GeoDataFrame polygons = [ Polygon([(0, 0), (5, 0), (5, 5), (0, 5)]), ] gdf_polygons = gpd.GeoDataFrame({'geometry': polygons}) # Create points GeoDataFrame points = [ Point(1, 1), Point(3, 4), Point(4, 2), ] gdf_points = gpd.GeoDataFrame({'geometry': points, 'label': ['School', 'Hospital', 'Shop']}) # Plot polygons ax = gdf_polygons.plot(color='lightyellow', edgecolor='black', figsize=(6, 6)) # Overlay points gdf_points.plot(ax=ax, color='red', marker='o', markersize=80, label='Locations of Interest') # Annotate points for x, y, label in zip(gdf_points.geometry.x, gdf_points.geometry.y, gdf_points['label']): plt.text(x + 0.1, y, label, fontsize=10) plt.title("Locations of Interest Overlayed on Polygon Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.legend() plt.show()
copy

1. Which library does GeoPandas use for plotting maps?

2. How can you change the color of features in a GeoPandas plot?

question mark

Which library does GeoPandas use for plotting maps?

Select the correct answer

question mark

How can you change the color of features in a GeoPandas plot?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 1
some-alt