File tree 2 files changed +37
-0
lines changed 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ def __init__(self):
162
162
self ._clippath = None
163
163
self ._clipon = True
164
164
self ._label = ''
165
+ self ._aria = None
165
166
self ._picker = None
166
167
self ._rasterized = False
167
168
self ._agg_filter = None
@@ -1053,6 +1054,35 @@ def set_in_layout(self, in_layout):
1053
1054
"""
1054
1055
self ._in_layout = in_layout
1055
1056
1057
+ def get_aria (self ):
1058
+ """Return any ARIA properties assigned to the artist"""
1059
+ return dict (self ._aria )
1060
+
1061
+ def set_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
+ if not isinstance (aria , dict ):
1075
+ if aria is not None :
1076
+ raise TypeError (
1077
+ f'aria must be dict or None, not { type (aria )} ' )
1078
+ self ._aria = aria
1079
+
1080
+ def update_aria (self , ** aria ):
1081
+ """Update WAI-ARIA properties on the artist."""
1082
+ # TODO validation
1083
+ for k , v in aria .items ():
1084
+ self ._aria [k ] = v
1085
+
1056
1086
def get_label (self ):
1057
1087
"""Return the label used for this artist in the legend."""
1058
1088
return self ._label
Original file line number Diff line number Diff line change @@ -535,3 +535,10 @@ def test_format_cursor_data_BoundaryNorm():
535
535
assert img .format_cursor_data (v ) == label
536
536
537
537
plt .close ()
538
+
539
+
540
+ def test_set_aria ():
541
+ art = martist .Artist ()
542
+ with pytest .raises (TypeError , match = '^aria must be dict' ):
543
+ art .set_aria ([])
544
+ art .set_aria (dict (label = "artist alt text" ))
You can’t perform that action at this time.
0 commit comments