Inky phat inverting colours at end of program

Using inkyPHAT on RPI Zero with below code I created to see if I can create some bar graphs.
I’m puzzled on why it draws inverted? at the end of the program it corrects with BLACK background and WHITE line?

import time
from PIL import Image, ImageDraw
from import auto

def draw_line(line_width, speed):
# Initialize the InkyPHAT object
inky_display = auto()

# Create a new PIL image object with a black background
img ="P", (inky_display.WIDTH, inky_display.HEIGHT), inky_display.BLACK)
draw = ImageDraw.Draw(img)

# Calculate the y-coordinate for the center of the line
y_center = inky_display.HEIGHT // 2

# Loop to animate the drawing of the line
for x in range(0, inky_display.WIDTH, speed):
    # Draw a vertical line segment with the specified width at the current position
    draw.rectangle((x, y_center - line_width // 2, x + speed, y_center + line_width // 2), fill=inky_display.WHITE)
    # Update the display every 10 iterations to speed up the animation
    if x % 10 == 0:
        # Set the image on the InkyPHAT display and show it
    # Pause before drawing the next segment
    time.sleep(0.01)  # Reduced sleep time

Get the line width and speed as input from the user

line_width = int(input("Enter the width of the line in pixels: "))
speed = int(input("Enter the speed of the animation (1 for fastest, higher for slower): "))

Call the function with the user-specified values

draw_line(line_width, speed)