我的情况很简单,我认为我的解决方案太复杂了,很可能会丢失一些东西。假设我有time
,位置(x,y,z),角度(滚动,俯仰,偏航)和速度的度量。我想要一个像现在一样简单的可视化效果,其中速度图可以用作“画笔”以动态放大前两个图。
我在vega编辑器中的情节的一个小例子可以在这里找到。
现在,每个点都是一个对象
{
"pitch": -0.006149084584096612,
"roll": 0.0007914191778949736,
"speed": 4.747345444390669,
"time": 0.519741,
"x": -0.01731604791076788,
"y": 0.020068310429957575,
"yaw": 0.0038123065311157552,
"z": -0.016005977140476142
}
在许多数据点的情况下,仅用于重复列名就需要大量内存。更好的是将数据具有以下形式
{
"time": [t1, t2, t3, ...],
"x": [...],
...
}
but vega's "row first" representation doesn't allow for that. I already asked on Slack where someone suggested to use Fold
and Pivot
, but I'm not sure how to implement this. Is it possible to use data that are stored as arrays? I'm creating the data myself from a C++ program and I'm free to export a different representation easily. The only question is how do I make vega-lite understand?
If I had time-series data with an "indicator column", I could create plots that combine several graphs easily. Unfortunately, I don't have that and the only solution I found is to use layers. With this, I have to set the colours for different graphs explicitly (instead of using schemes) and I don't get a legend.
如果层实际上是唯一的选择,例如将x,y,z合并成一个“运动”图,那么如何获得该图例的图例,告诉我红色-> x,绿色-> y和蓝色-> z?
答案是肯定的。
第一个问题的关键是以密集格式传递数据并使用Flatten变换对其进行扩展。
第二个问题的关键是使用折叠转换将多列转换为一个指标加一个值。
这是单个图表(在编辑器中打开)的演示:
{
"data": {
"values": [
{
"time": [1, 2, 3, 4],
"x": [5, 4, 5, 2],
"y": [2, 3, 2, 4],
"z": [1, 2, 1, 0]
}
]
},
"transform": [
{"flatten": ["time", "x", "y", "z"]},
{"fold": ["x", "y", "z"], "as": ["column", "value"]}
],
"mark": "line",
"encoding": {
"x": {"field": "time", "type": "quantitative"},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "column", "type": "nominal"}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句