Question: Is there a simple was to create a colorscale for CircleMarker coordinates using Dash Leaflet?

I’m wondering if anyone has a simpler method for creating a colorscale for the circlemarkers using Dash Leaflet. It only accepts a string for the color value input, so I can’t use the altitude data column as the variable.

The GeoJSON solution seems very complex.

        df_flight = pd.read_json(jsonFlightData, orient = 'split')
        df_flight.dropna() 
        grid_markers = df_flight[[LatValue, LongValue]].to_numpy()
        AltitudeData = df_flight[[AltValue]].to_numpy()
        df_flight["AltOffset"] = AltitudeData - AltOffset
        ColorbarMax = df_flight["AltOffset"].max()
        ColorbarMin = df_flight["AltOffset"].min()
        flightCoords = [dl.CircleMarker(id={'type': 'marker', 'index': indx}, center=grid_markers[indx], radius=1, stroke=False, color="#e8eef3", fillOpacity=100) for indx, key in enumerate(grid_markers)]
        

I’m trying to plot altitude data, and would like the marker color to vary with height.

I created a function that takes the normalised data and assigns a string value to the corresponding row.

Seems to work ok!

The styling of the points isn’t the best when it’s overlapping. Will need to tweak it to be clearer. I want the highest points to be clearly displayed.

        #####################################
        # Latitude, Longitude and Altitude data
        #####################################        
        df_flight = pd.read_json(jsonFlightData, orient = 'split')        
        df_flight.dropna() 
        grid_markers = df_flight[[LatValue, LongValue]].to_numpy()
        AltitudeData = df_flight[[AltValue]].to_numpy()
        df_flight["AltOffset"] = AltitudeData - AltOffset
        ColorbarMax = df_flight["AltOffset"].max()
        ColorbarMin = df_flight["AltOffset"].min()
        # Normalise altitude values
        df_flight["AltNormalise"] = (df_flight["AltOffset"] - ColorbarMin) / (ColorbarMax - ColorbarMin)
        # Assign colorscale to altitude value
        df_flight["AltColor"] = df_flight.apply(defineAltColor, axis=1)


#####################################
# Assigns colorscale to normalised altitude data
#####################################
def defineAltColor(AltNormValue):
    colorscale = [[0, "#fde725"],[1/9,"#b5de2b"],[2/9,"#6ece58"],[3/9,"#35b779"],[4/9,"#1f9e89"],[5/9,"#26828e"],[6/9,"#31688e"],[7/9,"#3e4989"],[8/9,"#482878"],[1,"#440154"]]
    for indx, value in enumerate(colorscale):
        if AltNormValue["AltNormalise"] <= value[0]:
            return value[1]
1 Like