This repository was archived by the owner on Nov 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Nov 25, 2021. It is now read-only.
Shaded Plot Image #14
Copy link
Copy link
Closed
Description
This would require datashader, including this isn't a "need," curious people's thoughts?
import datashader as ds
import datashader.transfer_functions as tf
import xarray as xr
from collections import OrderedDict
def datashader_large_time(df,height=300,width=900):
"""Use datashader to render an image off a large time series"""
if isinstance(df.index, pd.DatetimeIndex):
floats = df.index.values.astype(float)/ 1E9
df.index = floats-floats[0]
df.index.name = 'timestamp'
x_range = (df.index[0], df.index[-1])
y_range = (df.min(axis=1).min(), 1.2*df.max(axis=1).max())
cvs = ds.Canvas(x_range=x_range, y_range=y_range, plot_height=height, plot_width=width)
cols = df.columns
aggs = OrderedDict((c, cvs.line(df.reset_index(), df.index.name, c)) for c in cols)
imgs = [tf.shade(aggs[i]) for i in cols]
renamed = [aggs[key].rename({key: 'value'}) for key in aggs]
merged = xr.concat(renamed, 'cols')
total = tf.shade(merged.sum(dim='cols'), how='linear')
return imgs, total
def shaded_plot(df,height=300,width=900):
imgs, total = datashader_large_time(df,height=height,width=width)
fig = px.imshow(total,
color_continuous_scale =[[0.0, '#6914F0'],
[0.2, '#3764FF'],
[0.4, '#2DB473'],
[0.6, '#FAC85F'],
[0.8, '#EE7F27'],
[1, 'rgba(255,255,255,0)'] ],
origin='lower')
fig.update_layout(
width=width+80*2,
height=height+180 )
return fig
Metadata
Metadata
Assignees
Labels
No labels