Giter Site home page Giter Site logo

[ENH] Drivers colors about fast-f1 HOT 7 OPEN

manpean avatar manpean commented on June 12, 2024
[ENH] Drivers colors

from fast-f1.

Comments (7)

Casper-Guo avatar Casper-Guo commented on June 12, 2024 1

Discussion is at #218

from fast-f1.

theOehrly avatar theOehrly commented on June 12, 2024

Yes, this is a long-standing issue. But not that easy to solve, as you notice, when reading the other discussion. I hope to get this fixed for next season. But there won't be any noticeable progress before that.

from fast-f1.

manpean avatar manpean commented on June 12, 2024

Hi, I have read the discussion and tried to generate different colors by changing the lightness, but it was not successful. I am thinking that we can use the TeamColor in the DriverList for the teams.

I have found a list of 20 simple colors that enables easy contrasting. We can assign a color for each driver, however the driver's color will vary in every session, and it might seem strange to see HAM in red and VER in orange...

It solves the year-color problems, prevents similar colors, and eliminates the need to add colors manually when a new driver joins a session

Let me know your thoughts about it

from fast-f1.

Casper-Guo avatar Casper-Guo commented on June 12, 2024

I feel that defeats the purpose of providing driver colors. They are given in the plotting module for consistency. Also in this case each driver is strongly associated with their team color, I doubt many user will use the new color mapping if that association is not guarenteed

from fast-f1.

theOehrly avatar theOehrly commented on June 12, 2024

@manpean I agree with @Casper-Guo. That's not a solution most people are interested in.

from fast-f1.

manpean avatar manpean commented on June 12, 2024

Hi again,

I have been testing a new code.

The team's colors are converted from hex to CIELab. For each team color, the code searches for a color that fulfills three conditions:

The Delta_E between the color and other team colors must be higher than 'diff'.
The Delta_E between the color and the same team color must be lower than 'similar_s'.
The Delta_E between the color and the same team color must be higher than 'similar_i'.
The colors are generated by iterating through RGB values. However, this code has two problems:

It is not efficient; it has three nested 'for' loops, and each loop iterates 256 times, resulting in 16,777,216 possible colors.
As I have simplified the iterations to make it faster, if the conditions are too restrictive, the code may not find a solution.
Attached is a plot generated using this code where: diff=4; similar_s=6; similar_i=3

Colors

I attach the code, maybe you can find a better way to do it.

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import colorspacious

from fastf1 import plotting

plt.rcParams.update(plt.rcParamsDefault)
plotting.setup_mpl()



TEAM_COLORS = ["#358C75", "#F91536", "#F58020", "#6CD3BF", "#5E8FAA", "#3671C6", 
    "#B6BABD", "#2293D1", "#37BEDD", "#C92D4B"]

TEAMS=["Aston Martin", "Ferrari", "Mclaren", "Mercedes", "Alpha Tauri", "Red Bull",
       "Haas", "Alpine", "Williams", "Alfa Romeo"]


diff=4              #Minimun difference color with other team colors
similar_s=6         #Maximun difference between the team colors
similar_i=3         #Minimun difference between the team colors

Lab_colors = list()
Results = list()

for color in TEAM_COLORS:
    color_rgb = colors.hex2color(color)
    color_lab = colorspacious.cspace_convert(color_rgb, "sRGB1", "CAM02-UCS")
    
    Lab_colors.append(color_lab)

for i in range(len(Lab_colors)):
    stop_loops=False
    for r in range(32):
        # print(f"r: {r}")
        for g in range(32):
            for b in range(32):
                color_rgb = colorspacious.cspace_convert(Lab_colors[i], "CAM02-UCS", "sRGB1")
                color_lab = colorspacious.cspace_convert(((color_rgb[0]+r*8/256)%1, (color_rgb[1]+g*8/256)%1, (color_rgb[2]+b*8/256)%1), "sRGB1", "CAM02-UCS")

                if all(colorspacious.deltaE(color_lab, otro_color) > diff and colorspacious.deltaE(color_lab, Lab_colors[i]) < similar_s and colorspacious.deltaE(color_lab, Lab_colors[i]) > similar_i for index, otro_color in enumerate(Lab_colors) if index != i):
                    color_rgb = colorspacious.cspace_convert(color_lab, "CAM02-UCS", "sRGB1")
                    color_hex = colors.to_hex(color_rgb)
                    TEAM_COLORS.append(color_hex)
                    Lab_colors.append(color_lab)
                    Results.append([TEAM_COLORS[i], color_hex])
                    stop_loops=True
                    print(f"Color {i+1} found: ({r/256},{g/256},{b/256})\nDiff:{colorspacious.deltaE(color_lab, Lab_colors[i])}\n")
                    break

                if stop_loops:
                    break  
            if stop_loops:
                break  
        if stop_loops:
            break
        

fig = plt.figure()
ax = fig.add_subplot()

for i, pair in enumerate(Results):
    for j, color in enumerate(pair):
        ax.plot([0, 1], [i+j*0.15, i+j*0.15], color=color, linewidth=4, markerfacecolor='black', markeredgecolor='black', marker='o')

ax.set_yticks(range(0, len(Results)))
ax.set_yticklabels(TEAMS)

# plt.savefig("Colors", dpi=300)
plt.show()

# print(Results) 

from fast-f1.

manpean avatar manpean commented on June 12, 2024

@Casper-Guo I have read an article that explains how the difference between colors are measured using Delta E

The code I attached uses Delta E 1976, it means that Delta E is the lenght of the vector that starts in color 1 and ends in color 2 in a 3D space.

from fast-f1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.