Ok. @jessegrabowski helped me out with this post: PyMC+ArviZ: how to make the most of labeled coords and dims in PyMC 4.0 - Sharing - PyMC Discourse
I do have a multi-index with my hierarchical model that’s six levels deep.
I did the following to my arviz object:
idata.posterior_predictive.coords.update({'predicted_eaches_dim_0':m_idx})
idata.observed_data.coords.update({'predicted_eaches_dim_0':m_idx})
idata = idata.assign_coords(
obs_id=m_idx, # note also different length
groups=["constant_data"]
)
That yielded the following:
So now I have repeating values for each level of my hierarchy plus the month and location of the sale made. When I run the below, I get the following.
az.plot_ppc(idata, flatten=[], coords = {'predicted_eaches_dim_0':'NUTRITION'},
kind = 'scatter')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_85434/3645245510.py in <module>
1 az.plot_ppc(idata, flatten=[], coords = {'predicted_eaches_dim_0':'NUTRITION'},
----> 2 kind = 'scatter')
/opt/conda/lib/python3.7/site-packages/arviz/plots/ppcplot.py in plot_ppc(data, kind, alpha, mean, observed, color, colors, grid, figsize, textsize, data_pairs, var_names, filter_vars, coords, flatten, flatten_pp, num_pp_samples, random_seed, jitter, animated, animation_kwargs, legend, labeller, ax, backend, backend_kwargs, group, show)
354 # TODO: Add backend kwargs
355 plot = get_plotting_function("plot_ppc", "ppcplot", backend)
--> 356 axes = plot(**ppcplot_kwargs)
357 return axes
/opt/conda/lib/python3.7/site-packages/arviz/plots/backends/matplotlib/ppcplot.py in plot_ppc(ax, length_plotters, rows, cols, figsize, animated, obs_plotters, pp_plotters, predictive_dataset, pp_sample_ix, kind, alpha, colors, textsize, mean, observed, jitter, total_pp_samples, legend, labeller, group, animation_kwargs, num_pp_samples, backend_kwargs, show)
98 backend_kwargs.setdefault("squeeze", True)
99 if ax is None:
--> 100 fig, axes = create_axes_grid(length_plotters, rows, cols, backend_kwargs=backend_kwargs)
101 else:
102 axes = np.ravel(ax)
/opt/conda/lib/python3.7/site-packages/arviz/plots/backends/matplotlib/__init__.py in create_axes_grid(length_plotters, rows, cols, backend_kwargs)
53 backend_kwargs = {**backend_kwarg_defaults(), **backend_kwargs}
54
---> 55 fig, axes = subplots(rows, cols, **backend_kwargs)
56 extra = (rows * cols) - length_plotters
57 if extra > 0:
/opt/conda/lib/python3.7/site-packages/matplotlib/pyplot.py in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1454 axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
1455 squeeze=squeeze, subplot_kw=subplot_kw,
-> 1456 gridspec_kw=gridspec_kw)
1457 return fig, axs
1458
/opt/conda/lib/python3.7/site-packages/matplotlib/figure.py in subplots(self, nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw)
894 if gridspec_kw is None:
895 gridspec_kw = {}
--> 896 gs = self.add_gridspec(nrows, ncols, figure=self, **gridspec_kw)
897 axs = gs.subplots(sharex=sharex, sharey=sharey, squeeze=squeeze,
898 subplot_kw=subplot_kw)
/opt/conda/lib/python3.7/site-packages/matplotlib/figure.py in add_gridspec(self, nrows, ncols, **kwargs)
1445
1446 _ = kwargs.pop('figure', None) # pop in case user has added this...
-> 1447 gs = GridSpec(nrows=nrows, ncols=ncols, figure=self, **kwargs)
1448 self._gridspecs.append(gs)
1449 return gs
/opt/conda/lib/python3.7/site-packages/matplotlib/gridspec.py in __init__(self, nrows, ncols, figure, left, bottom, right, top, wspace, hspace, width_ratios, height_ratios)
385 super().__init__(nrows, ncols,
386 width_ratios=width_ratios,
--> 387 height_ratios=height_ratios)
388
389 _AllowedKeys = ["left", "bottom", "right", "top", "wspace", "hspace"]
/opt/conda/lib/python3.7/site-packages/matplotlib/gridspec.py in __init__(self, nrows, ncols, height_ratios, width_ratios)
51 if not isinstance(ncols, Integral) or ncols <= 0:
52 raise ValueError(
---> 53 f"Number of columns must be a positive integer, not {ncols!r}")
54 self._nrows, self._ncols = nrows, ncols
55 self.set_height_ratios(height_ratios)
ValueError: Number of columns must be a positive integer, not 0
NUTRITION
is in the glbl_bus_ln_desc
coordinate that is near the top of the arviz object but when I put that in the coordinate argument, the error states I only can use predicted_eaches_dim_0
.
It looks as if I have everything I want in the object, but accessing it continues to be an issue.
Do you see what I’m doing wrong?