Skip to content

options for plottingยค

the default table representation should have an accompanying form to it. in this notebook, we design a common pattern form changes views of stylized tables. radio groups and checkbox groups are useful for these styling choicess.

from nbconvert_a11y.repr import get_table, new, TableOptions
from nbconvert_a11y.table import aria
bs4.Tag._repr_html_ = bs4.Tag.prettify

df = DataFrame(numpy.random.randn(30, 3), None, list("xyz"))
df.iloc[0] *= 0 
df.iloc[-1] = df.iloc[:-1].mean()
section = df.T.pipe(get_table, id="xyz", options=TableOptions(figcaption=TableOptions.Position.last))
section.table.attrs.update(**{"class": "xyz"})
/home/tbone/mambaforge/envs/p311/lib/python3.11/site-packages/pandas/core/algorithms.py:1743: RuntimeWarning: divide by zero encountered in log10
  return lib.map_infer(values, mapper, convert=convert)
%%

    options = {
        "color everything red": 
```css
#xyz {color: red;}
```
        , "big text": 
```css
#xyz{font-size: 300%;}
```

    }
%%
    update_view =\
```text/javascript
document.querySelectorAll(`[name=%s][aria-controls]`).forEach((object)=>{    
    var target = document.getElementById(object.getAttribute(`aria-controls`));
    (target.tagName == `STYLE`) && target.setAttribute("media", object.checked ? "all" : "none");
});
```
update_view =\
document.querySelectorAll(`[name=%s][aria-controls]`).forEach((object)=>{    
    var target = document.getElementById(object.getAttribute(`aria-controls`));
    (target.tagName == `STYLE`) && target.setAttribute("media", object.checked ? "all" : "none");
});
def choices(options, name, id=None, kind="radio", default=0):
    id = "xyz"
    ul = new("ul")
    for i, (label, css) in enumerate(options.items()):
        id = F"{id}-{name}-style"
        ul.append(new("li", new("label", new("input", type=kind, name=name, onchange=update_view%name, **aria(controls=id)), label), new("style", css, id=id, media="none")))
    return ul
section.form.append(choices(options, "views"))
section.form.append(choices(options, "checks", kind="checkbox"))
section
pandas dataframe with 3 rows, 30 columns with 1 index levels and 1 columns levels.
None 0 1 2 3 4 5 6 7 8 9 20 21 22 23 24 25 26 27 28 29
'x' -0.000 -0.404 -2.047 -2.503 1.834 -0.077 0.325 0.442 0.549 -0.729 -1.124 -0.657 0.479 -0.216 0.077 1.086 0.977 -0.540 0.709 -0.128
'y' 0.000 -0.439 -1.571 0.191 0.849 -0.542 0.928 -0.282 -2.562 2.019 -0.259 -1.791 -1.308 -0.487 0.998 -1.437 1.536 0.042 -1.644 -0.216
'z' 0.000 -0.655 1.006 2.197 1.266 0.891 -1.519 -1.391 -0.580 -0.178 1.158 1.044 -1.158 0.530 1.886 0.726 -0.713 -0.099 0.261 0.063
min 0.000 -0.655 -2.047 -2.503 0.849 -0.542 -1.519 -1.391 -2.562 -0.729 -1.124 -1.791 -1.308 -0.487 0.077 -1.437 -0.713 -0.540 -1.644 -0.216
max 0.000 -0.404 1.006 2.197 1.834 0.891 0.928 0.442 0.549 2.019 1.158 1.044 0.479 0.530 1.886 1.086 1.536 0.042 0.709 0.063
diff 0.000 0.252 3.053 4.700 0.985 1.432 2.448 1.833 3.111 2.748 2.282 2.835 1.787 1.017 1.809 2.524 2.249 0.581 2.353 0.278