Good Evening,
Wanted to ask how people are incorporating subscripts/superscripts/hats in variable names in idata / digraphs etc. I can’t seem to find a lot of resources on restrictions in this matter, so anything would be appreciated!
Good Evening,
Wanted to ask how people are incorporating subscripts/superscripts/hats in variable names in idata / digraphs etc. I can’t seem to find a lot of resources on restrictions in this matter, so anything would be appreciated!
Thank you for the assist! Excited to see what they have worked up
For the digraphs I don’t know. For variable and coordinate names, ArviZ uses custom labeller classes to process the strings and they are sent to the plotting backend. I would recommend using these classes (for example MapLabeller
or a custom one) to handle that. This page has the tutorial on ArviZ labeling: Label guide — ArviZ 0.22.0 documentation. This section specifically has an example about using MapLabeller
to use latex syntax when generating plots with ArviZ.
For full context, xarray supports any hashable as a variable name, so any string is valid but also tuples for example. You can define a variable name as $\theta$
, ArviZ will pass that to matplotlib as is (unless you customize the labeller) and it will render as the greek letter. But that also means that in the code you’ll need to use:
idata.posterior["$\theta$"].mean()
# on the other hand, using theta instead allows using either
idata.posterior["theta"].mean()
idata.posterior.theta.mean()
Moreover, you will often run into issues when things are passed elsewhere. For example, /
in variable names implicitly define groups in netcdf/zarr, so i/o for datasets with such variables will generally break (or at best they won’t round trip). Similarly, using a dollar sign in a variable name indicates matplotlib to trigger latex syntax which might not be the desired if the dollar are units for example.