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

Holoviews colors and colorbar based on datetimes

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

有人知道怎么做吗?

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

示例:

我通过使用参数用日期覆盖颜色条的刻度标签来解决这个问题:

 colorbar_opts={
     'major_label_overrides'={}
 }

这是一个工作示例(已简化):

# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas

# create sample data
X = np.random.normal(size=(2, 1000))

df = pd.DataFrame(
    data={
        'col1': X[0],
        'col2': X[1],
        # use 'date' to overwirte the ticklabels of the colorbar
        'date': pd.date_range(start='2017-01-01', freq='D', periods=1000),
    }
)

# use 'time_color' for the colorbar, since the colors need to be a float or int
df['time_color'] = df.index.to_series()


# draw scatter plot
# using the 'time_color' column to color the markers
# and overwrite the tick label using the date column

cbar_opts = dict(
                major_label_overrides  = df['date'].dt.strftime('%Y-%m-%d').to_dict(),
                major_label_text_align = 'left',
                )

hv_coloured = df.hvplot.points(x='col1', y='col2', c='time_color'
                              ).opts(colorbar_opts=cbar_opts, cmap='viridis')

hv_coloured 


如果您执行“hv.help(hv.Points)”,您可以获得有关颜色条周围所有可用选项的更多解释:

colorbar:
Whether to display a colorbar.

colorbar_opts:
Allows setting specific styling options for the colorbar overriding the options defined in the colorbar_specs class attribute. Includes location, orientation, height, width, scale_alpha, title, title_props, margin, padding, background_fill_color and more.

colorbar_position: Allows selecting between a number of predefined colorbar position options. The predefined options may be customized in the colorbar_specs class attribute.


这个问题为我指明了正确的方向:

How do I manually set the tick locations of a colorbar for a Points plot in HoloViews?