Longitude and latitude scale next to axes are not correct in a Mercator map created with geopandas (Python3).
I made a Mercator-projecrioned map with geopandas like this.
import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world[(world.name != "Antarctica") & (world.name != "Fr. S. Antarctic Lands")]
world = world.to_crs("EPSG:3395")
ax = world.plot()
ax.set_title("Mercator")
plt.show()
The map itself was correctly output, but longitude/latitude scales next to axes were incorrect as in images below.
Longitude is supposed to range -180 to 180, and latitude -90 to 90. However, scales in the image don't do so.
How could I get correctly output scales?
EPSG:3395 is a mercator (cylindrical) projection with units of metres. You need a cylindrical projection in units of degrees (which is called a Plate Carree or Equidistant Cylindrical projection). Use EPSG:4326 - For example see https://geopandas.readthedocs.io/en/latest/docs/user_guide/projections.html
More info on EPSG:4326 here: https://epsg.io/4326
More info on EPSG:3395 here: https://epsg.io/3395
Discussion of Mercator compared to Plate Carree (aka Platte Carre) https://idvux.wordpress.com/2007/06/06/mercator-vs-well-not-mercator-platte-carre/
To draw geographic graticule (lines of meridian and parallels of latitude), and label them with values in degrees you can use cartopy
gridlines() function. Here is the modified code and the output plot.
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
myproj = ccrs.Mercator()
pcproj = ccrs.PlateCarree()
fig = plt.figure(figsize=(16, 7))
extent =[-179,179, -78, 85] #lonmin, lonmax, latmin, latmax
ax = plt.axes(projection=myproj )
ax.set_extent(extent, crs=pcproj)
lon_grid = np.arange(-180, 180, 30)
lat_grid = np.arange(-75, 83, 15)
gl = ax.gridlines(draw_labels=True,
xlocs=lon_grid, ylocs=lat_grid,
x_inline=False, y_inline=False,
color='k', linestyle='dotted')
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
antarctica = world[world.name == "Antarctica"].to_crs("EPSG:3395") #just in case
world = world[(world.name != "Antarctica") & (world.name != "Fr. S. Antarctic Lands")]
world = world.to_crs("EPSG:3395")
ax = world.plot(ax=ax, edgecolor='k', lw=0.3)
# if you prefer to plot `Antarctica`
if True:
antarctica.plot(ax=ax, color='lightgray')
ax.set_title("Mercator")
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.