@@ -340,7 +340,7 @@ def plot_confusion_matrix(
340340 n_labels = len (labels )
341341
342342 # Color strip thickness in data coordinates (fraction of a cell)
343- strip_size = 0.4
343+ strip_size = 0.8
344344
345345 # Move x-axis labels to top if requested
346346 if xlabel_position == "top" :
@@ -349,7 +349,7 @@ def plot_confusion_matrix(
349349 plt .setp (ax .get_xticklabels (), rotation = 90 , ha = "center" , va = "bottom" )
350350
351351 # Draw color strips using rectangles in data coordinates
352- # Place strips at the edge of the heatmap, inside the plot area
352+ # Note: imshow has origin='upper', so y-axis is inverted (y=0 at top)
353353 for i , color in enumerate (colors_list ):
354354 # Left strip (y-axis, true labels) - placed at x=-0.5 edge
355355 rect_left = Rectangle (
@@ -363,9 +363,10 @@ def plot_confusion_matrix(
363363 ax .add_patch (rect_left )
364364
365365 # Top or bottom strip (x-axis, predicted labels)
366+ # y-axis is inverted: smaller y = visually at top
366367 if xlabel_position == "top" :
367368 rect_x = Rectangle (
368- (i - 0.5 , n_labels - 0.5 ),
369+ (i - 0.5 , - 0.5 - strip_size ),
369370 1 ,
370371 strip_size ,
371372 facecolor = color ,
@@ -374,7 +375,7 @@ def plot_confusion_matrix(
374375 )
375376 else :
376377 rect_x = Rectangle (
377- (i - 0.5 , - 0.5 - strip_size ),
378+ (i - 0.5 , n_labels - 0.5 ),
378379 1 ,
379380 strip_size ,
380381 facecolor = color ,
0 commit comments