python - 基于日期时间的 Holoviews 颜色和颜色条
问题描述
我是全息视图和散景的新手,我正在尝试根据颜色基于日期的时间序列创建散点图。类似于此页面上的第三个代码单元: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:
是否显示颜色条。
colorbar_opts:
允许为颜色条设置特定的样式选项,覆盖在 colorbar_specs 类属性中定义的选项。包括位置、方向、高度、宽度、scale_alpha、title、title_props、margin、padding、background_fill_color 等等。
colorbar_position:允许在多个预定义的颜色条位置选项之间进行选择。可以在 colorbar_specs 类属性中自定义预定义选项。
这个问题为我指明了正确的方向:
推荐阅读
- r - 为每条边查找间接节点(在 R 中)
- git - 如何从 Github 历史记录中删除本地不存在的提交?
- sql - posgresql json_agg 里面的 json_agg
- javascript - 如何使用 alpine.js 复制表单
- roblox - 我的变量值不会在我的脚本上更新
- python - 'tuple' 对象没有属性 'random_split'
- sql - Postgresql 加密
- breeze - BreezeJs 将 +1 添加到 [ConcurrencyCheck] 标记的字段
- css - 如何在 Scenebuilder 中使用焦点属性?
- node.js - 让 Apollo 解析器在启动时监听 mqtt 代理