pydata / pydata/xarray

Update Facetgrid api to match seaborn

Open
#10,176 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Something I assumed would work:
g = ds.plot(hue="level", col="time")
# Second plot uses the existing FacetGrid's axes
ds2.plot(ax=g.axes.flat, hue="level", col="time")

Gives ValueError: Can't use axes when making faceted plots.

How I currectly do it:

Xarray's plotting with facets doesn't work the same way as seaborn's FacetGrid. You currently need to use a manual approach, such as :

g = ds.plot(hue="level", col="time")
for i in range(ds2.time.size):
    ax = g.axs.flat[i]
    ax.set_prop_cycle(None)
    ds2.isel(time=i).plot(ax=ax, hue="level")
More generally:

I think it would be nice to have the functionalities seaborn's facetgrid has, notably passing a facetgrid to the plotting function directly but also including the utility functions that handle the legend or labels to be able to have nice better plots without changing the datasets themselves.

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 by reviewing xarray's existing faceted plotting API and seaborn's FacetGrid behavior, especially how axes, legends, and labels are handled. Done would include support for passing an existing FacetGrid and the requested plotting utilities, but the issue does not identify files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.