0

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?

1 Answer 1

0

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
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.