Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbc7472

Browse files
tonyfasttacaswell
authored andcommitted
Add wai-aria property to the artist accessibility annotations.
1 parent6ed3ab1 commitfbc7472

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎lib/matplotlib/artist.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def __init__(self):
162162
self._clippath=None
163163
self._clipon=True
164164
self._label=''
165+
self._aria=None
165166
self._picker=None
166167
self._rasterized=False
167168
self._agg_filter=None
@@ -1053,6 +1054,35 @@ def set_in_layout(self, in_layout):
10531054
"""
10541055
self._in_layout=in_layout
10551056

1057+
defget_aria(self):
1058+
"""Return any ARIA properties assigned to the artist"""
1059+
returndict(self._aria)
1060+
1061+
defset_aria(self,aria):
1062+
"""
1063+
Set ARIA properties to the artist.
1064+
1065+
A primary use of this method is to attach aria-label to the artist to
1066+
provide alt text to figures.
1067+
1068+
Parameters
1069+
----------
1070+
aria : dict
1071+
1072+
"""
1073+
# TODO validation
1074+
ifnotisinstance(aria,dict):
1075+
ifariaisnotNone:
1076+
raiseTypeError(
1077+
f'aria must be dict or None, not{type(aria)}')
1078+
self._aria=aria
1079+
1080+
defupdate_aria(self,**aria):
1081+
"""Update WAI-ARIA properties on the artist."""
1082+
# TODO validation
1083+
fork,vinaria.items():
1084+
self._aria[k]=v
1085+
10561086
defget_label(self):
10571087
"""Return the label used for this artist in the legend."""
10581088
returnself._label

‎lib/matplotlib/tests/test_artist.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,10 @@ def test_format_cursor_data_BoundaryNorm():
535535
assertimg.format_cursor_data(v)==label
536536

537537
plt.close()
538+
539+
540+
deftest_set_aria():
541+
art=martist.Artist()
542+
withpytest.raises(TypeError,match='^aria must be dict'):
543+
art.set_aria([])
544+
art.set_aria(dict(label="artist alt text"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp