【发布时间】:2022-01-03 20:50:09
【问题描述】:
我正在使用 Altair,并希望使用子字符串搜索过滤数据。 Here 是在 vega-lite 中执行此操作的示例。代码如下:
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"data": {"name": "d"},
"mark": "point",
"encoding": {
"x": {"type": "quantitative", "field": "xval", "scale":{"domain": [0,4]}},
"y": {"type": "quantitative", "field": "yval", "scale":{"domain": [1,10]}}
},
"params": [{"name": "Letter", "value": "A",
"bind": {"input": "select", "options": ["A", "B", "C", "D", "E", "F"]}
}],
"transform": [
{"filter": "indexof(datum.info, Letter)>-1"}
],
"datasets": {
"d": [
{"xval": 1, "yval": 7, "info": "A;B;D;E"},
{"xval": 2, "yval": 2, "info": "A;C;E;F"},
{"xval": 3, "yval": 9, "info": "A;B;D"}
]
}
}
这允许我过滤掉 info 列中包含“A”、“B”、“C”等的行,但它依赖于 "params",它在 Altair 中是 not available - 还有其他的吗到目前为止,如何在 Altair 中实现这种“子字符串”过滤?这只是一个最小的例子,但在我的实际用例中,我有大量的“选项”(许多基因名称),因此在原始数据中为每个选项添加一列是不可行的。
尝试在 Altair 中执行此操作,因为它是针对我认为允许 Altair 但不允许 vega-lite 的可执行研究文章。
【问题讨论】: