-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add "alt" to supported image metadata keys #646
base: master
Are you sure you want to change the base?
Conversation
{%- set alt = output.metadata[datatype].alt %} | ||
{%- if alt %} | ||
:alt: {{ alt }} | ||
{%- endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please verify that what I've done here with {%-
vs {%
is appropriate -- I'm not 100% sure about the effect on whitespace in the intermediate RST.
Hmm, the doc example is not ideal in that it's calling fig, ax = plt.subplots(figsize=[6, 3])
ax.plot([4, 9, 7, 20, 6, 33, 13, 23, 16, 62, 8]);
display(fig, metadata={"image/png": {"width": "150px", "height": "100px",
"alt": "this is my alt text"}}) but this displays the figure twice. Is there some way to get a cell like this to only display the figure once? I'd rather not resort to |
Well, typical usage would be to not use If you want to avoid the automatic display, you can do this after the plt.close(fig) But I guess this is even less typical usage. To add the metadata directly in the same cell as the plot, I guess this would have to be incorporated into the |
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"display(fig, metadata={\"image/png\": {\"width\": \"150px\", \"height\": \"100px\",\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JupyterLab, it looks like those values have to be integers, not strings with "px". Otherwise they have no effect.
Also, if both are given, height
seems to be ignored.
In the nbsphinx
output that's different.
"outputs": [], | ||
"source": [ | ||
"display(fig, metadata={\"image/png\": {\"width\": \"150px\", \"height\": \"100px\",\n", | ||
" \"alt\": \"this is my alt text\"}})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alt
attribute doesn't seem to be supported by JupyterLab, or am I doing something wrong?
Thanks @mgeier, maybe I should take a step back and outline my use case. What I want to be able to do is specify figure alt text as unobtrusively as possible in a notebook code cell and use that notebook with
I think this would only work if the matplotlib backends knew what to do with the metadata, right? matplotlib/matplotlib#21328 would add basic aria information to matplotlib's Also, is this |
There seems to be a somewhat related workshop tomorrow: https://mail.python.org/pipermail/matplotlib-users/2022-May/002078.html |
Hi @mgeier, this PR allows alt text to be specified in a code cell and end up in the resulting HTML. Alt text is important for accessibility purposes as it is used by screen readers in place of the image itself. It also adds a docs example for
width
andheight
(which I think are currently not present in the docs?) as well asalt
.Also, I only looked at HTML output for this as I'm a lot less familiar with the latex side of sphinx output. Not sure it matters, just pointing that out in case it does!
Let me know if anything else is needed here; happy to push updates if so :)