TransWikia.com

Plotting xarray over background map using cartopy

Geographic Information Systems Asked by Bielorusse on March 1, 2021

I am trying to plot an xarray DataArray over a background map using cartopy.
When including the background map, the DataArray is not visible, although the map has an appropriate extent.

I am adding the background map using cimgt and geo_axes.add_image().
This method has worked for me before when plotting points with plt.scatter().

The data array has dimensions x (100 values) and y (140 values), and contains np.nans and floats.

Here is my code:

# DataArray creation
# ...

# create figure
fig = plt.figure()

# create geo axes
projection = ccrs.epsg(32630)
geo_axes = plt.subplot(projection=projection)

# add open street map background
# when commenting the two following lines, the data array is plotted correctly
osm_background = cimgt.OSM()
geo_axes.add_image(osm_background, 10)

# plot dataset
xr.plot.imshow(
    darray=dataset.velocity.mean(dim="time"),
    x="x",
    y="y",
    ax=geo_axes,
    transform=projection,
)

# show plot
plt.show()

I can’t seem to find what is causing the issue. Has anyone encountered this before, or can anyone see what I am doing wrong?

One Answer

I was missing the zorder argument in imshow to make this layer on top.

The following works correctly:

# plot dataset
xr.plot.imshow(
    darray=dataset.velocity.mean(dim="time"),
    x="x",
    y="y",
    ax=geo_axes,
    transform=projection,
    zorder=10
)

Correct answer by Bielorusse on March 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP