-
Hi, I have defined from plotnine import *
import polars as pl
import geopandas as gp
def overlay_color(rgb_hex_colors, light="white", dark="black", threshold=0.5):
"""
Decide which color is suitable to write onto the given colors
"""
def luminance(rgb_hex):
"""
Calculate the Luminance ([0, 1]) of a hex color
"""
r = int(rgb_hex[1:3], 16)
g = int(rgb_hex[3:5], 16)
b = int(rgb_hex[5:], 16)
luma = (r*0.299 + g*0.587 + b*0.0722) / 256
return luma
return [light if luminance(x) < threshold else dark for x in rgb_hex_colors] But when I run
I have this error. What's wrong in my code?? Thank you
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I have added this
and edited the geom_text
And it works. But why can't I use the code in the plotnine example? |
Beta Was this translation helpful? Give feedback.
-
color=stage("costo_per_km2", after_scale="overlay_color(color)") Should be in a mapping i.e. In the |
Beta Was this translation helpful? Give feedback.
-
Just change color to fill. fill=stage("costo_per_km2", after_scale="overlay_color(fill)") |
Beta Was this translation helpful? Give feedback.
Should be in a mapping i.e. In the
aes()
call.