Holoviews基于日期时间的颜色和颜色栏

时间:2019-12-10 12:47:10

标签: python time-series bokeh scatter-plot holoviews

我是全息视图和散景的新手,我正在尝试根据时间序列创建散点图,其中颜色基于日期。类似于此页上的第三个代码单元:https://docs.pymc.io/notebooks/GLM-rolling-regression.html

有人知道怎么做吗?

Ps:我需要使用带有bokeh后端的全息视图。

示例:
holoviews colorbar based on datetime

1 个答案:

答案 0 :(得分:2)

我正在通过使用参数

用日期覆盖颜色栏的刻度标签来解决此问题
 colorbar_opts={
     'major_label_overrides'={}
 }

这是一个可行的示例:

# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh')

# create sample data
df = pd.DataFrame(
    data={
        'col1': np.random.normal(size=1000),
        'col2': np.random.normal(size=1000),
        # use 'range' for the colorbar, since the colors need to be a float or int
        'range': range(0, 1000),
        # use 'date' to overwirte the ticklabels of the colorbar
        'date': pd.date_range(start='2017-01-01', freq='D', periods=1000),
    }
)

# draw scatter plot
# using the range column to color the markers
# and overwrite the tick label using the date column
hv.Scatter(
    data=df, 
    kdims=['col1'],
    vdims=['col2', 'range', 'date'],
).opts(
    width=500,
    color='range', 
    colorbar=True, 
    colorbar_opts={
        'major_label_overrides': 
            {i * 200: df['date'].dt.strftime('%Y-%m-%d').iloc[i*200] for i in range(0, 5)},
        'major_label_text_align': 'left',
    },
)


如果您进行hv.help(hv.Scatter),则可以获取有关颜色栏所有可用选项的更多说明:

  

颜色条:
  是否显示颜色条。

     

colorbar_opts:
  允许为颜色条覆盖设置特定的样式选项   colorbar_specs类属性中定义的选项。包括   位置,方向,高度,宽度,scale_alpha,标题,title_props,   边距,填充,background_fill_color等。

     

colorbar_position:   允许在多个预定义之间进行选择   彩条位置选项。预定义的选项可以在   colorbar_specs类属性。


这个问题为我指明了正确的方向:
How do I manually set the tick locations of a colorbar for a Points plot in HoloViews?