`FacetGrid` plot overlaying multiple variables from same dataset?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
I'm trying to produce a facet plot which contains maps with different overlaid layers (e.g. a pcolormesh and streamplot).
At the moment I'm creating the plot and then iterating over the axes to add the plots manuallay
p = dss['LH'].plot.pcolormesh(
x='lon',
y='lat',
col="exp",
)
for i, ax in enumerate(p.axes.flat):
ax.coastlines()
ax.streamplot(
dss.isel(exp=i).lon.values,
dss.isel(exp=i).lat.values,
dss.isel(exp=i)['u_10m_gr'].values,
dss.isel(exp=i)['v_10m_gr'].values,
)
This is far from optimal and doesn't really look clean to me. Also, I'm not entirely sure the order of p.axes.flat correspond to the one of the exp dimension I'm using to facet.
All examples in the doc (https://docs.xarray.dev/en/stable/user-guide/plotting.html) refer to the plot method of DataArray, so it seems that, once created the p object, no other variable from the dataset can be accessed.
However, on the doc it is mentioned
TODO: add an example of using the map method to plot dataset variables (e.g., with plt.quiver).
It is not clear to me whether the xarray.plot.FacetGrid.map method can indeed be used to plot another dataset variable or not. If that's not the case, is there any way to achieve what I'm doing without manually looping through the axes?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the plotting guide and the xarray.plot.FacetGrid.map method, focusing on the documented TODO about plotting dataset variables. Determine whether mapping another variable onto each facet is supported and document the supported approach, or clarify the limitation and recommended alternative. Done means the guide answers this use case without requiring readers to infer the facet ordering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100