-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coords for pairs of variables. #1627
Comments
Pointwise or non-slice selection with xarray is something that always feels very complicated to me, with very obscure docs. You should be able to perform pointwise selection using DataArrays whose dimension is not present in the xarray object you want to index. Here is an example. Our dataset has 4 dimensions, and we want to perform pointwise selection with values over 2 of them (I think it should work with as many dims as desired though). import xarray as xr
import arviz as az
ds = az.dict_to_dataset(
{"s": np.random.normal(size=(4, 100, 3, 2))},
dims={"s": ["time", "sensor"]},
coords={"sensor": ["A", "B"]}
) Output:
We can now select a subset with: coords = {
'sensor': xr.DataArray(['A', 'A', 'B'], dims=['pointwise_sel']),
'time': xr.DataArray([0, 2, 2], dims=['pointwise_sel'])
}
ds.sel(coords) whose output is:
ArviZ uses az.plot_posterior(ds, coords=coords) There is one important caveat though, which is that now the original coordinate values that we used for indexing have been converted to coordinated without dimension, and they are not shown in the plot. As a comparison: az.plot_posterior(ds) With the latest (yet to be released at the time of writing) updates to ArviZ, you could define custom labellers to take care of that. See the label guide for info on labellers and installation guide for info on installing the development version. And thanks for reporting! I think I'll use this as the example for the last section of the label guide 😄 The emerging idea/pattern could be: subset_ds = ds.sel(coords)
# some extra work to get the "proper" labels
labeller = # define labeller with the processed ds
az.plot_xyz(subset_ds, labeller=labeller) |
Thanks, that's awesome! I'll give that a try Any idea if it's possible to hack some sort of custom labelling in v0.11.0? I'm stuck with that to make arviz play nice with PyMC3... |
I don't think it's possible :/. What may be easier is to get latest ArviZ to play nice with old PyMC3 if you are interested in submitting a PR for that. I think that the only breaking incompatibility is that we removed If you are willing to take this on and locally test on your older pymc3 versions, submitting a PR to add |
Ah, okay, thanks for explaining that. If I get the chance, I will attempt the PR, but seeing as this is quite a new package I might as well also force an update to the latest versions of pymc and arviz once the custom labellers are available and I have figured out how to use them :) Thanks for all the help! |
I have added a PR to extend the label guide and show how to keep the right labels #1635 |
I'm trying to do some clean up, so I'll close this as it seems resolved, feel free to reopen if it is not the case. |
Short Description
HI! I'm trying to understand how I can make the coords keyword of many arviz plotting routines to behave in a certain way. I hope explain the problem well enough, I'll gladly try to clarify if not.
To outline my problem, I'm inferring the contents of a correlation matrix with PyMC3. Now, because the matrix is symmetrical, I only want to use the upper (or lower, if it makes a difference) off-diagonal elements, that is to use elements [0,1], [1,2], [0,2] if it's a 3-dimensional problem.
However, plot_pair seems to interpret coords as a "slice" along a dimension, such that if I set coords to [0,1] on dimension one of the correlation matrix and [1,2] on dimension two, I will also get the plots for [1,1]. Is there any way that I can leave this one out automatically, or do I have to manually iterate over a set of axes to get this?
Code Example or link
Here's a short example, you can find a more complete version of the code for context in this repo.
Thanks in advance for any input you can give me!
The text was updated successfully, but these errors were encountered: