@@ -1068,6 +1068,244 @@ def test_legend_labelcolor_rcparam_markerfacecolor_short():
1068
1068
assert mpl .colors .same_color (text .get_color (),color )
1069
1069
1070
1070
1071
+ def test_legend_labelcolor_linecolor_histograms ():
1072
+ x = np .arange (10 )
1073
+
1074
+ # testing c kwarg for bar, step, and stepfilled histograms
1075
+ fig ,ax = plt .subplots ()
1076
+ _ ,_ ,h = ax .hist (x ,histtype = 'bar' ,color = 'r' ,
1077
+ label = "red bar hist with a red label" )
1078
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1079
+ tc = leg .texts [0 ].get_color ()
1080
+ assert mpl .colors .same_color (tc ,'r' )
1081
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1082
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1083
+
1084
+ fig ,ax = plt .subplots ()
1085
+ _ ,_ ,h = ax .hist (x ,histtype = 'step' ,color = 'g' ,
1086
+ label = "green step hist with a green label" )
1087
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1088
+ tc = leg .texts [0 ].get_color ()
1089
+ assert mpl .colors .same_color (tc ,'g' )
1090
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_edgecolor ())
1091
+ assert mpl .colors .same_color (tc ,h [0 ].get_edgecolor ())
1092
+
1093
+ fig ,ax = plt .subplots ()
1094
+ _ ,_ ,h = ax .hist (x ,histtype = 'stepfilled' ,color = 'b' ,
1095
+ label = "blue stepfilled hist with a blue label" )
1096
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1097
+ tc = leg .texts [0 ].get_color ()
1098
+ assert mpl .colors .same_color (tc ,'b' )
1099
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1100
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1101
+
1102
+ # testing c, fc, and ec combinations for bar histograms
1103
+ fig ,ax = plt .subplots ()
1104
+ _ ,_ ,h = ax .hist (x ,histtype = 'bar' ,color = 'r' ,ec = 'b' ,
1105
+ label = "red bar hist with blue edges and a red label" )
1106
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1107
+ tc = leg .texts [0 ].get_color ()
1108
+ assert mpl .colors .same_color (tc ,'r' )
1109
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1110
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1111
+
1112
+ fig ,ax = plt .subplots ()
1113
+ _ ,_ ,h = ax .hist (x ,histtype = 'bar' ,fc = 'r' ,ec = 'b' ,
1114
+ label = "red bar hist with blue edges and a red label" )
1115
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1116
+ tc = leg .texts [0 ].get_color ()
1117
+ assert mpl .colors .same_color (tc ,'r' )
1118
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1119
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1120
+
1121
+ fig ,ax = plt .subplots ()
1122
+ _ ,_ ,h = ax .hist (x ,histtype = 'bar' ,fc = 'none' ,ec = 'b' ,
1123
+ label = "unfilled blue bar hist with a blue label" )
1124
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1125
+ tc = leg .texts [0 ].get_color ()
1126
+ assert mpl .colors .same_color (tc ,'b' )
1127
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_edgecolor ())
1128
+ assert mpl .colors .same_color (tc ,h [0 ].get_edgecolor ())
1129
+
1130
+ # testing c, and ec combinations for step histograms
1131
+ fig ,ax = plt .subplots ()
1132
+ _ ,_ ,h = ax .hist (x ,histtype = 'step' ,color = 'r' ,ec = 'b' ,
1133
+ label = "blue step hist with a blue label" )
1134
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1135
+ tc = leg .texts [0 ].get_color ()
1136
+ assert mpl .colors .same_color (tc ,'b' )
1137
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_edgecolor ())
1138
+ assert mpl .colors .same_color (tc ,h [0 ].get_edgecolor ())
1139
+
1140
+ fig ,ax = plt .subplots ()
1141
+ _ ,_ ,h = ax .hist (x ,histtype = 'step' ,ec = 'b' ,
1142
+ label = "blue step hist with a blue label" )
1143
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1144
+ tc = leg .texts [0 ].get_color ()
1145
+ assert mpl .colors .same_color (tc ,'b' )
1146
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_edgecolor ())
1147
+ assert mpl .colors .same_color (tc ,h [0 ].get_edgecolor ())
1148
+
1149
+ # testing c, fc, and ec combinations for stepfilled histograms
1150
+ fig ,ax = plt .subplots ()
1151
+ _ ,_ ,h = ax .hist (x ,histtype = 'stepfilled' ,color = 'r' ,ec = 'b' ,
1152
+ label = "red stepfilled hist, blue edges, red label" )
1153
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1154
+ tc = leg .texts [0 ].get_color ()
1155
+ assert mpl .colors .same_color (tc ,'r' )
1156
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1157
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1158
+
1159
+ fig ,ax = plt .subplots ()
1160
+ _ ,_ ,h = ax .hist (x ,histtype = 'stepfilled' ,fc = 'r' ,ec = 'b' ,
1161
+ label = "red stepfilled hist, blue edges, red label" )
1162
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1163
+ tc = leg .texts [0 ].get_color ()
1164
+ assert mpl .colors .same_color (tc ,'r' )
1165
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1166
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1167
+
1168
+ fig ,ax = plt .subplots ()
1169
+ _ ,_ ,h = ax .hist (x ,histtype = 'stepfilled' ,fc = 'none' ,ec = 'b' ,
1170
+ label = "unfilled blue stepfilled hist, blue label" )
1171
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1172
+ tc = leg .texts [0 ].get_color ()
1173
+ assert mpl .colors .same_color (tc ,'b' )
1174
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_edgecolor ())
1175
+ assert mpl .colors .same_color (tc ,h [0 ].get_edgecolor ())
1176
+
1177
+ fig ,ax = plt .subplots ()
1178
+ _ ,_ ,h = ax .hist (x ,histtype = 'stepfilled' ,fc = 'r' ,ec = 'none' ,
1179
+ label = "edgeless red stepfilled hist with a red label" )
1180
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1181
+ tc = leg .texts [0 ].get_color ()
1182
+ assert mpl .colors .same_color (tc ,'r' )
1183
+ assert mpl .colors .same_color (tc ,leg .get_patches ()[0 ].get_facecolor ())
1184
+ assert mpl .colors .same_color (tc ,h [0 ].get_facecolor ())
1185
+ plt .close ('all' )
1186
+
1187
+
1188
+ def test_legend_labelcolor_linecolor_plot ():
1189
+ x = np .arange (5 )
1190
+
1191
+ # testing line plot
1192
+ fig ,ax = plt .subplots ()
1193
+ p = ax .plot (x ,c = 'r' ,label = "red line with a red label" )
1194
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1195
+ tc = leg .texts [0 ].get_color ()
1196
+ assert mpl .colors .same_color (tc ,'r' )
1197
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_color ())
1198
+ assert mpl .colors .same_color (tc ,p [0 ].get_color ())
1199
+
1200
+ # testing c, fc, and ec combinations for maker plots
1201
+ fig ,ax = plt .subplots ()
1202
+ p = ax .plot (x ,'o' ,c = 'r' ,label = "red circles with a red label" )
1203
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1204
+ tc = leg .texts [0 ].get_color ()
1205
+ assert mpl .colors .same_color (tc ,'r' )
1206
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_color ())
1207
+ assert mpl .colors .same_color (tc ,p [0 ].get_color ())
1208
+
1209
+ fig ,ax = plt .subplots ()
1210
+ p = ax .plot (x ,'o' ,c = 'r' ,mec = 'b' ,label = "red circles, blue edges, red label" )
1211
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1212
+ tc = leg .texts [0 ].get_color ()
1213
+ assert mpl .colors .same_color (tc ,'r' )
1214
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_color ())
1215
+ assert mpl .colors .same_color (tc ,p [0 ].get_color ())
1216
+
1217
+ fig ,ax = plt .subplots ()
1218
+ p = ax .plot (x ,'o' ,mfc = 'r' ,mec = 'b' ,label = "red circles, blue edges, red label" )
1219
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1220
+ tc = leg .texts [0 ].get_color ()
1221
+ assert mpl .colors .same_color (tc ,'r' )
1222
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_markerfacecolor ())
1223
+ assert mpl .colors .same_color (tc ,p [0 ].get_markerfacecolor ())
1224
+
1225
+ # 'none' cases
1226
+ fig ,ax = plt .subplots ()
1227
+ p = ax .plot (x ,'o' ,mfc = 'none' ,mec = 'b' ,label = "blue unfilled circles, blue label" )
1228
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1229
+ tc = leg .texts [0 ].get_color ()
1230
+ assert mpl .colors .same_color (tc ,'b' )
1231
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_markeredgecolor ())
1232
+ assert mpl .colors .same_color (tc ,p [0 ].get_markeredgecolor ())
1233
+
1234
+ fig ,ax = plt .subplots ()
1235
+ p = ax .plot (x ,'o' ,mfc = 'r' ,mec = 'none' ,label = "red edgeless circles, red label" )
1236
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1237
+ tc = leg .texts [0 ].get_color ()
1238
+ assert mpl .colors .same_color (tc ,'r' )
1239
+ assert mpl .colors .same_color (tc ,leg .get_lines ()[0 ].get_markerfacecolor ())
1240
+ assert mpl .colors .same_color (tc ,p [0 ].get_markerfacecolor ())
1241
+
1242
+ fig ,ax = plt .subplots ()
1243
+ p = ax .plot (x ,'o' ,c = 'none' ,label = "invisible circles with invisible label" )
1244
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1245
+ tc = leg .texts [0 ].get_color ()
1246
+ assert tc == 'none'
1247
+ assert tc == leg .get_lines ()[0 ].get_markerfacecolor ()
1248
+ assert tc == leg .get_lines ()[0 ].get_markeredgecolor ()
1249
+ assert tc == leg .get_lines ()[0 ].get_color ()
1250
+ assert tc == p [0 ].get_markerfacecolor ()
1251
+ assert tc == p [0 ].get_markeredgecolor ()
1252
+ assert tc == p [0 ].get_color ()
1253
+ plt .close ('all' )
1254
+
1255
+
1256
+ def test_legend_labelcolor_linecolor_scatter ():
1257
+ x = np .arange (5 )
1258
+
1259
+ # testing c, fc, and ec combinations for scatter plots
1260
+ fig ,ax = plt .subplots ()
1261
+ p = ax .scatter (x ,x ,c = 'r' ,label = "red circles with a red label" )
1262
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1263
+ tc = leg .texts [0 ].get_color ()
1264
+ assert mpl .colors .same_color (tc ,'r' )
1265
+ assert mpl .colors .same_color (tc ,leg .legend_handles [0 ].get_facecolor ())
1266
+ assert mpl .colors .same_color (tc ,p .get_facecolor ())
1267
+
1268
+ fig ,ax = plt .subplots ()
1269
+ p = ax .scatter (x ,x ,c = 'r' ,ec = 'b' ,label = "red circles, blue edges, red label" )
1270
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1271
+ tc = leg .texts [0 ].get_color ()
1272
+ assert mpl .colors .same_color (tc ,'r' )
1273
+ assert mpl .colors .same_color (tc ,leg .legend_handles [0 ].get_facecolor ())
1274
+ assert mpl .colors .same_color (tc ,p .get_facecolor ())
1275
+
1276
+ fig ,ax = plt .subplots ()
1277
+ p = ax .scatter (x ,x ,fc = 'r' ,ec = 'b' ,label = "red circles, blue edges, red label" )
1278
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1279
+ tc = leg .texts [0 ].get_color ()
1280
+ assert mpl .colors .same_color (tc ,'r' )
1281
+ assert mpl .colors .same_color (tc ,leg .legend_handles [0 ].get_facecolor ())
1282
+ assert mpl .colors .same_color (tc ,p .get_facecolor ())
1283
+
1284
+ # 'none' cases
1285
+ fig ,ax = plt .subplots ()
1286
+ p = ax .scatter (x ,x ,fc = 'none' ,ec = 'b' ,label = "blue unfilled circles, blue label" )
1287
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1288
+ tc = leg .texts [0 ].get_color ()
1289
+ assert mpl .colors .same_color (tc ,'b' )
1290
+ assert mpl .colors .same_color (tc ,leg .legend_handles [0 ].get_edgecolor ())
1291
+ assert mpl .colors .same_color (tc ,p .get_edgecolor ())
1292
+
1293
+ fig ,ax = plt .subplots ()
1294
+ p = ax .scatter (x ,x ,fc = 'r' ,ec = 'none' ,label = "red edgeless circles, red label" )
1295
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1296
+ tc = leg .texts [0 ].get_color ()
1297
+ assert mpl .colors .same_color (tc ,'r' )
1298
+ assert mpl .colors .same_color (tc ,leg .legend_handles [0 ].get_facecolor ())
1299
+ assert mpl .colors .same_color (tc ,p .get_facecolor ())
1300
+
1301
+ fig ,ax = plt .subplots ()
1302
+ p = ax .scatter (x ,x ,c = 'none' ,label = "invisible circles with invisible label" )
1303
+ leg = ax .legend (loc = 1 ,labelcolor = 'linecolor' )
1304
+ tc = leg .texts [0 ].get_color ()
1305
+ assert tc == 'none'
1306
+ plt .close ('all' )
1307
+
1308
+
1071
1309
@pytest .mark .filterwarnings ("ignore:No artists with labels found to put in legend" )
1072
1310
def test_get_set_draggable ():
1073
1311
legend = plt .legend ()