简体   繁体   中英

Cartopy Mercator plot

I wanna create a scatter plot of data on a map in Mercator projection. It only prints the empty map without values if I set the Projection in Mercator. It is, however, no problem if I choose the PlateCarree projection....

Works fine:

ax1=plt.axes(projection=ccrs.PlateCarree())
ax1.add_feature(cf.BORDERS)
ax1.add_feature(cf.COASTLINE)
ax1.add_feature(cf.BORDERS)
ax1.add_feature(cf.STATES)
ax1.set_extent([-5, 10, 41, 52], crs=ccrs.PlateCarree())
ax1.set_title('xxx', fontsize=18);
ax1.grid(b=True, alpha=0.5)
obs200.plot(x="longitude", y="latitude", kind="scatter", c="mm", ax=ax1, cmap = "jet",
       figsize=(18,20), title="xxx") # latitude: Breitengrad, longitude: Längengrad

prints empty map:

ax1=plt.axes(projection=ccrs.Mercator())
ax1.add_feature(cf.BORDERS)
ax1.add_feature(cf.COASTLINE)
ax1.add_feature(cf.BORDERS)
ax1.add_feature(cf.STATES)
ax1.set_extent([-5, 10, 41, 52], crs=ccrs.Mercator())
ax1.set_title('xxx', fontsize=18);
ax1.grid(b=True, alpha=0.5)
obs200.plot(x="longitude", y="latitude", kind="scatter", c="mm", ax=ax1, cmap = "jet",
       figsize=(18,20), title="xxx") # latitude: Breitengrad, longitude: Längengrad

I couldn't find my example in other questions

A demonstration of geodataframes plotted on Mercator projection.

import cartopy.crs as ccrs
import geopandas as gpd
import matplotlib.pyplot as plt

# These are Geodataframes with world/city data
# Their CRS is ccrs.PlateCarree()
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
city_pnts = gpd.read_file(gpd.datasets.get_path("naturalearth_cities"))

# Geometries in the 2 Geodataframes have CRS transformed
#  to Mercator projection here
mercator = ccrs.Mercator()
wld2 = world.to_crs(mercator.proj4_init)
cty2 = city_pnts.to_crs(mercator.proj4_init)

# Plot them with matplotlib
#  with projection = ccrs.Mercator()
fig, ax2 = plt.subplots(figsize=[8,6], subplot_kw=dict(projection=mercator))
ax2.add_geometries(wld2['geometry'], crs=mercator, facecolor='sandybrown', edgecolor='black')

# Use ax2 to plot other data
cty2.plot(ax=ax2, zorder=20)

# This sets extent of the plot
ax2.set_extent([-15, 25, 30, 60], crs=ccrs.PlateCarree())

输出图

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM