Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Created September 23, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinuxIsCool/4235c447c1dbd336a148442840258c6f to your computer and use it in GitHub Desktop.
Save LinuxIsCool/4235c447c1dbd336a148442840258c6f to your computer and use it in GitHub Desktop.
Gradient colored area plot with holoviz
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