Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to overlap a geopandas dataframe with basemap?

$
0
0

I have a shapefile that I read as a geopandas dataframe

import geopandas as gpdgdf = gpd.read_file('myfile.shp')gdf.plot()

enter image description here

where gdf.crs

<Projected CRS: ESRI:54009>Name: World_MollweideAxis Info [cartesian]:- E[east]: Easting (metre)- N[north]: Northing (metre)Area of Use:- name: World.- bounds: (-180.0, -90.0, 180.0, 90.0)Coordinate Operation:- name: World_Mollweide- method: MollweideDatum: World Geodetic System 1984- Ellipsoid: WGS 84- Prime Meridian: Greenwich

and gdf.total_bounds

array([-17561329.90352868,  -6732161.66088735,  17840887.22672861,         8750122.26961274])

I would like to use basemap to plot the lat/lon grid on top of it. This is what I am doing

from mpl_toolkits.basemap import Basemap# Create a Basemap instance with the same projection as the GeoDataFramemap = Basemap(projection='moll', lon_0=-0, lat_0=-0, resolution='c')# Create a figure and axisfig, ax = plt.subplots(figsize=(10, 6))# Plot the basemapmap.drawcoastlines()map.drawcountries()map.drawparallels(range(-90, 91, 30), labels=[1,0,0,0], fontsize=10)map.drawmeridians(range(-180, 181, 60), labels=[0,0,0,1], fontsize=10)# Plot the GeoDataFrame on top of the basemapgdf.plot(ax=ax, color='red', markersize=5)

but this is what I get

enter image description here


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>