pydata / pydata/xarray

set_boundary removes data from axis on faceting plots

Open
#4,137 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

I experienced that when using FacetGrid plots and if I want to apply a boundary to the axes, the data from the plots get removed.

A short example to illustrate this:

import xarray as xr
import matplotlib.path as mpath
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import numpy as np

ds = xr.tutorial.load_dataset('air_temperature')

data = ds.air.isel(time=range(0,2))
p = data.plot(transform=ccrs.PlateCarree(),
            y="lat", x="lon",
            col='time', col_wrap=2,
            subplot_kws={'projection': ccrs.NorthPolarStereo()}
)

theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)

for ax in p.axes.flat:
    ax.coastlines()
    ax.gridlines()
    ax.set_extent([-180,180, 50,90], crs=ccrs.PlateCarree())
    #ax.set_boundary(circle, transform=ax.transAxes)

With the last line I want to have a circle as a boundary of each axis. This works but the data are not shown anymore:

Commenting the last line in the example shows the data as expected but without the boundary of course:

Any hints on why this isn't working?

Cheers,
Markus

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided FacetGrid reproduction, especially the loop over p.axes.flat and the ax.set_boundary(circle, transform=ax.transAxes) call. Trace how the plotted data, Matplotlib axes, and Cartopy boundary interact; done means applying the circular boundary to every faceted axis without making the plotted data disappear.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.