@@ -1017,7 +1017,11 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
1017
1017
.. versionadded:: 3.7
1018
1018
1019
1019
label_props : dict, optional
1020
- Dictionary of `.Text` properties to be used for the labels.
1020
+ Dictionary of `.Text` properties to be used for the labels. Per dict
1021
+ key, if the value is a list or a tuple, its length should be the
1022
+ amount of labels, and then a value per label is set. If the dict's
1023
+ value is not a list or a tuple, the same property value is applied
1024
+ to all labels
1021
1025
1022
1026
.. versionadded:: 3.7
1023
1027
frame_props : dict, optional
@@ -1050,12 +1054,12 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
1050
1054
1051
1055
ys = np .linspace (1 , 0 , len (labels )+ 2 )[1 :- 1 ]
1052
1056
1053
- label_props = _expand_text_props (label_props )
1054
1057
self .labels = [
1055
1058
ax .text (0.25 , y , label , transform = ax .transAxes ,
1056
1059
horizontalalignment = "left" , verticalalignment = "center" ,
1057
- ** props )
1058
- for y , label , props in zip (ys , labels , label_props )]
1060
+ )
1061
+ for y , label in zip (ys , labels )]
1062
+ self .set_label_props (label_props )
1059
1063
text_size = np .array ([text .get_fontsize () for text in self .labels ]) / 2
1060
1064
1061
1065
frame_props = {
@@ -1117,12 +1121,26 @@ def set_label_props(self, props):
1117
1121
Parameters
1118
1122
----------
1119
1123
props : dict
1120
- Dictionary of `.Text` properties to be used for the labels.
1124
+ Dictionary of `.Text` properties, just like `label_props` argument
1125
+ of __init__ function.
1121
1126
"""
1122
1127
_api .check_isinstance (dict , props = props )
1123
1128
props = _expand_text_props (props )
1124
- for text , prop in zip (self .labels , props ):
1125
- text .update (prop )
1129
+ for propk ,propv in props .items ():
1130
+ if isinstance (propv , (list , tuple )):
1131
+ if len (propv ) != len (self .labels ):
1132
+ raise ValueError (
1133
+ f"When setting labels' property { propk } , we "
1134
+ f"encountered a { type (propv )} as a label dict value, "
1135
+ "with a length different from the amount of labels. "
1136
+ "Please use a single value, or a list of values per "
1137
+ "label."
1138
+ )
1139
+ for text ,propv_single in zip (self .labels , propv ):
1140
+ text .update ({propk : propv_single })
1141
+ else :
1142
+ for text in self .labels :
1143
+ text .update ({propk : propv })
1126
1144
1127
1145
def set_frame_props (self , props ):
1128
1146
"""
0 commit comments