Some named color scales are capitalized like “Reds”, some not like “ice”, some mixed like “RdBu”.
when trying to iterate over color lists from all color scales, I need to use something like this:
def _get_color_scales():
all_attributes = dir(px.colors.sequential)
color_scales = []
for attr in all_attributes:
value = getattr(px.colors.sequential, attr)
if (
not attr.endswith("_r") and
value and
isinstance(value, list) and
isinstance(value[0], str) and
(value[0].startswith("rgb(") or
value[0].startswith("#"))
):
color_scales.append(attr)
return color_scales
for color_scale in _get_color_scales():
color_list = getattr(px.colors.sequential, color_scale)
instead of just iterating over px.colors.named_colorscales()
Is there another way of doing this slightly more elegant?