[Python] Visualise colour gradient based on histogram

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I feel like this is more of a math question. I have a programme which visualises distances and then draws them on a map, based on the hue spectre. The problem is that the distance values are not equally distributed and therefore, I only see a few colours of the spectre and it gets quite boring.

    Attached as photos are the result and the histogram. As you can see, most points are more in the 20-40% range.[​IMG][​IMG]

    My code of the colouring function is this one:

    def colour_gradient_from_distance(distance_array):
    spectre_size = 1 # number of iterations around rainbow, preferably < 1.0

    max_dist = numpy.amax(distance_array)
    min_dist = numpy.amin(distance_array)
    rangemm = max_dist - min_dist
    length = len(distance_array)
    colours = [None] * length

    for i in range(length):
    start = 0 # anything between 0 and 360
    hue = ((distance_array - min_dist) / rangemm + (start / 360)) % 1 * spectre_size

    colours = hue # only hue is changed, the other two are 1.0
    return colours


    It is quite a primitive function, but I have been through like 20 tries. I have tried logarithms, exponentials, linear functions, nothing really fixed this problem.

    Currently, I am trying to fix exactly this distribution here, but in a perfect world, it would work for all of them.

    Does anybody have smart inputs to this?

    Continue reading...

Compartilhe esta Página