-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Improve the accessibility of figures shown with _repr_html_
#15971
Comments
Adding a simple alt sounds reasonable. |
So i'd love to raise this issue from the 💀 ipython/ipython#12864 adds alt text to Image displays. This begs the question "where could the alt text live?" I'd love to move this issue along and would appreciate some advice. I'm not familiar with the
In the output image, the alt text would be assigned to the image with a change in the It seems like this could significantly impact a lot of documentation using notebooks or sphinx gallery, and provide extra surfaces for new-comers to contribute improvements. Is there a certain |
Could we grab it from the label? I think that the label is not used for anything on the Figures. |
If that feature doesn't get used for anything then I think it would be a solid place to infer the alt text from. i don't know enough about the _label_s usage, if y'all think its reasonable to appropriate it for alt text then we'd have a nice existing solution. |
In #17893 there's a discussion about a colorblind friendly attribute & possibly a spec to go with it, and I think for similar reasons it'd be good to have an explicit .alt_text attribute that can start as a string and possibly grow into a spec as the community coalesces around standards. I'm worried about using _label_s 'cause I think there's been some previous discussion on the calls about using the artist label attributes for some kind of artist management & now we have the subfigures too and I think it'd be better to keep that usage consistent. |
if that is the case then maybe it is worth considering adding an
i could imagine that with some thinking this abstraction could work its way into some of the interactive matplotlib views. |
I think adding adding this as an Skimming https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques it looks like most of them are not relevant to us (as our scope is much more limited that "arbitrary document / UI"). I propose a straw-man implementation of: def set_aria(self, aria: Dict[str, obj]):
# TODO validation
self._aria = aria
def update_aria(self, **aria):
# TODO validation
for k, v in aria.items():
self._aria[k] = v
def get_aria(self):
return dict(self._aria) I think we would want to keep |
As well as |
as it stands now,
|
Ah.. I should probably read up on accessibility best practice. My knowledge is probably a bit dated... |
Resolving this issue and defining a method for setting figure alt text will also allow for the Sphinx-Gallery Matplotlib scraper to be upgraded to use it. This will allow alt text to be used for plots in the examples gallery section of the documentation. Based on how Sphinx-Gallery is structured, there's no clear way to include alt text unless it's exposed via Matplotlib. Once an alt text method is defined, it also might make sense to default the |
I was running into some accessibility audit errors with Jupyter Book, and it made me realize that the
_repr_html_
method of Figures doesn't outputimg
elements that havealt
tags (something that screen readers like).It seems that the relevant code is here:
matplotlib/lib/matplotlib/figure.py
Line 378 in 59acd5c
and then uses the template that's referenced here:
matplotlib/lib/matplotlib/backends/backend_webagg.py
Line 289 in 690fd71
Maybe using this?
https://github.com/matplotlib/matplotlib/blob/be978a35932a9f303f3d60f14f52ed9df89334c5/lib/matplotlib/backends/web_backend/js/mpl.js
I wonder if this could be a relatively simple fix by making the figure title the
alt
tag by default, and if it doesn't exist, just making it something likeFigure
?The text was updated successfully, but these errors were encountered: