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

Commit2d28564

Browse files
committed
Add wai-aria property to the artist accessibility annotations.
1 parent3557392 commit2d28564

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎lib/matplotlib/artist.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def __init__(self):
161161
self._clippath=None
162162
self._clipon=True
163163
self._label=''
164+
self._aria=None
164165
self._picker=None
165166
self._rasterized=False
166167
self._agg_filter=None
@@ -1069,6 +1070,33 @@ def update(self, props):
10691070
self.stale=True
10701071
returnret
10711072

1073+
defget_aria(self):
1074+
"""Return any ARIA properties assigned to the artist"""
1075+
returndict(self._aria)
1076+
1077+
defset_aria(self,aria):
1078+
"""
1079+
Set ARIA properties to the artist.
1080+
1081+
A primary use of this method is to attach aria-label to the artist to provide alt text to figures.
1082+
1083+
Parameters
1084+
----------
1085+
aria : dict
1086+
"""
1087+
# TODO validation
1088+
ifnotisinstance(aria,dict):
1089+
ifariaisnotNone:
1090+
raiseTypeError(
1091+
f'aria must be dict or None, not{type(aria)}')
1092+
self._aria=aria
1093+
1094+
defupdate_aria(self,**aria):
1095+
"""Update WAI-ARIA properties on the artist"""
1096+
# TODO validation
1097+
fork,vinaria.items():
1098+
self._aria[k]=v
1099+
10721100
defget_label(self):
10731101
"""Return the label used for this artist in the legend."""
10741102
returnself._label

‎lib/matplotlib/tests/test_artist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,9 @@ class MyArtist4(MyArtist3):
374374
pass
375375

376376
assertMyArtist4.setisMyArtist3.set
377+
378+
deftest_set_aria():
379+
art=martist.Artist()
380+
withpytest.raises(TypeError,match='^aria must be dict'):
381+
art.set_aria([])
382+
art.set_aria(dict(label="artist alt text"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp