Created
January 31, 2022 12:14
-
-
Save ColdTeapot273K/5d8a96a80029f5cb0d6a4c57ffb70c7d to your computer and use it in GitHub Desktop.
Transform Plotly colorscale into something dark-theme-friendly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.express as px | |
palette = px.colors.sequential.Bluered.copy() | |
new_palette = list() | |
for color in palette: | |
orig_color = color[4:-1].split(",") | |
# offset = 50 | |
# offset = 75 | |
offset = 100 | |
orig_color = [np.clip(offset + int(color_elem), 0, 255) for color_elem in orig_color] | |
new_color = f"rgb{orig_color[0], orig_color[1], orig_color[2]}" | |
new_palette.append(new_color) | |
# --- | |
# Testing: | |
# Vanilla | |
df = px.data.tips() | |
fig = px.scatter(df, x="total_bill", y="tip", color="size", | |
title="Numeric 'size' values mean continuous color", color_continuous_scale=palette) | |
fig.show() | |
# New | |
fig = px.scatter(df, x="total_bill", y="tip", color="size", | |
title="Numeric 'size' values mean continuous color", color_continuous_scale=new_palette) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Old:
New: