Created
September 23, 2023 20:32
-
-
Save LinuxIsCool/4235c447c1dbd336a148442840258c6f to your computer and use it in GitHub Desktop.
Gradient colored area plot with holoviz
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 datashader as ds | |
import holoviews as hv | |
import hvplot.pandas | |
import numpy as np | |
import pandas as pd | |
import panel as pn | |
from holoviews.operation.datashader import datashade | |
# Sample data | |
np.random.seed(42) | |
df = pd.DataFrame({'x': np.arange(100), 'y': np.cumsum(np.random.randn(100))}) | |
# Create a gradient fill based on the 'y' value | |
def color_fn(data): | |
colors = hv.plotting.util.color_intervals(data.y, ['#0000ff', '#ff0000'], 256) | |
return colors | |
gradient_fill = datashade( | |
hv.Area(df, 'x', 'y'), aggregator=ds.mean('y'), color_fn=color_fn | |
) | |
# Create a Panel app | |
app = pn.panel(gradient_fill) | |
# Serve the app | |
app.servable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment