gpt4 book ai didi

vega-lite - 如何在穿孔卡片中使用所有圆圈大小?

转载 作者:行者123 更新时间:2023-12-04 10:04:44 24 4
gpt4 key购买 nike

This VEGA-lite demo Table Bubble Plot 使用所有大小,从小到大。

我的脚本(如下图所示)没有使用,只有 2 或 3 种尺寸。如何执行或对 VEGA-lite 说使用所有圆形尺寸?

enter image description here

{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": { "url":"/_sql/myTable"},
"mark": "circle",
"encoding": {
"y": {
"field": "instant",
"type": "ordinal",
"timeUnit": "day",
"sort": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
},
"x": {
"field": "instant",
"type": "ordinal",
"timeUnit": "hours"
},
"size": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "avg"
},
"color": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "avg"
}
}
}

PS:理想情况下也将“仅蓝色”渐变更改为 "bluegreen" ,但我不知道如何将颜色设置为颜色。

笔记

对于@Jim 请求,示例:
[{"instant":"2020-04-23T14:46:42","n_pmin":2210086}, 
{"instant":"2020-04-23T15:05:01","n_pmin":2214909},
{"instant":"2020-04-23T16:05:01","n_pmin":2159652},
{"instant":"2020-04-23T17:05:01","n_pmin":2290159},
{"instant":"2020-04-23T18:05:01","n_pmin":2235739},
{"instant":"2020-04-23T19:05:01","n_pmin":2505914},
{"instant":"2020-04-23T20:05:01","n_pmin":2517069},
{"instant":"2020-04-23T21:05:01","n_pmin":2492883},
{"instant":"2020-04-23T22:05:01","n_pmin":2535839},
{"instant":"2020-04-23T23:05:01","n_pmin":2519568},
{"instant":"2020-04-24T00:05:02","n_pmin":2367309},
{"instant":"2020-04-24T01:05:01","n_pmin":2384885},
{"instant":"2020-04-24T02:05:01","n_pmin":2340421},
{"instant":"2020-04-24T03:05:01","n_pmin":2369579},
{"instant":"2020-04-24T04:05:01","n_pmin":2285203},
{"instant":"2020-04-24T05:05:01","n_pmin":2206629},
{"instant":"2020-04-24T06:05:01","n_pmin":2149411},
{"instant":"2020-04-24T07:05:01","n_pmin":2218313},
{"instant":"2020-04-24T08:05:01","n_pmin":2231320},
{"instant":"2020-04-24T09:05:01","n_pmin":2163876},
{"instant":"2020-04-24T10:05:01","n_pmin":2100388},
{"instant":"2020-04-24T11:05:01","n_pmin":2040520},
{"instant":"2020-04-24T12:05:02","n_pmin":2157928},
{"instant":"2020-04-24T13:05:01","n_pmin":2099753},
{"instant":"2020-04-24T15:05:01","n_pmin":2334844},
{"instant":"2020-04-24T16:05:01","n_pmin":2430831},
{"instant":"2020-04-24T17:05:01","n_pmin":2403722},
{"instant":"2020-04-24T18:05:02","n_pmin":2468541},
{"...":"..."},
{"instant":"2020-05-13T16:05:01","n_pmin":2717164},
{"instant":"2020-05-13T17:05:01","n_pmin":2794972},
{"instant":"2020-05-13T18:05:01","n_pmin":2824981},
{"instant":"2020-05-13T19:05:01","n_pmin":2852586},
{"instant":"2020-05-13T20:05:01","n_pmin":2868170}]

最佳答案

对主要问题的简短回答,

How to enforce or say to VEGA-lite use all circle sizes?



"zero": false .但是,让我们更详细地了解如何以更手工的方式进行操作,以了解何时可以设置 scale.zerofalse作为更快的解决方案。

您可以使用 scale 调整您感兴趣的属性。相关编码中的规范。

对于配色方案,您可以设置 scale.schemeVega Color Schemes 中列出的任何选项.

对于尺寸,您可以设置 scale.domainscale.range到所需的值,其中 domain是数据空间中数字的跨度, range是以方形像素为单位的关联图例标记的面积。

或者,您可以设置 scale.zerofalse自动调整域,并忽略零值(这是导致图表中“缺失”圆圈的原因)。

使用您提供的示例数据 ( vega editor ) 将它们放在一起,它可能看起来像这样:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"values": [
{"instant": "2020-04-23T14:46:42", "n_pmin": 2210086},
{"instant": "2020-04-23T15:05:01", "n_pmin": 2214909},
{"instant": "2020-04-23T16:05:01", "n_pmin": 2159652},
{"instant": "2020-04-23T17:05:01", "n_pmin": 2290159},
{"instant": "2020-04-23T18:05:01", "n_pmin": 2235739},
{"instant": "2020-04-23T19:05:01", "n_pmin": 2505914},
{"instant": "2020-04-23T20:05:01", "n_pmin": 2517069},
{"instant": "2020-04-23T21:05:01", "n_pmin": 2492883},
{"instant": "2020-04-23T22:05:01", "n_pmin": 2535839},
{"instant": "2020-04-23T23:05:01", "n_pmin": 2519568},
{"instant": "2020-04-24T00:05:02", "n_pmin": 2367309},
{"instant": "2020-04-24T01:05:01", "n_pmin": 2384885},
{"instant": "2020-04-24T02:05:01", "n_pmin": 2340421},
{"instant": "2020-04-24T03:05:01", "n_pmin": 2369579},
{"instant": "2020-04-24T04:05:01", "n_pmin": 2285203},
{"instant": "2020-04-24T05:05:01", "n_pmin": 2206629},
{"instant": "2020-04-24T06:05:01", "n_pmin": 2149411},
{"instant": "2020-04-24T07:05:01", "n_pmin": 2218313},
{"instant": "2020-04-24T08:05:01", "n_pmin": 2231320},
{"instant": "2020-04-24T09:05:01", "n_pmin": 2163876},
{"instant": "2020-04-24T10:05:01", "n_pmin": 2100388},
{"instant": "2020-04-24T11:05:01", "n_pmin": 2040520},
{"instant": "2020-04-24T12:05:02", "n_pmin": 2157928},
{"instant": "2020-04-24T13:05:01", "n_pmin": 2099753},
{"instant": "2020-04-24T15:05:01", "n_pmin": 2334844},
{"instant": "2020-04-24T16:05:01", "n_pmin": 2430831},
{"instant": "2020-04-24T17:05:01", "n_pmin": 2403722},
{"instant": "2020-04-24T18:05:02", "n_pmin": 2468541},
{"instant": "2020-05-13T16:05:01", "n_pmin": 2717164},
{"instant": "2020-05-13T17:05:01", "n_pmin": 2794972},
{"instant": "2020-05-13T18:05:01", "n_pmin": 2824981},
{"instant": "2020-05-13T19:05:01", "n_pmin": 2852586},
{"instant": "2020-05-13T20:05:01", "n_pmin": 2868170}
]
},
"mark": "circle",
"encoding": {
"y": {
"field": "instant",
"type": "ordinal",
"timeUnit": "day",
"sort": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
},
"x": {"field": "instant", "type": "ordinal", "timeUnit": "hours"},
"size": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "mean",
"scale": {"domain": [2200000, 3000000], "range": [100, 500]}
},
"color": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "mean",
"scale": {"domain": [2200000, 3000000], "scheme": "bluegreen"}
}
}
}

enter image description here

动态数据的自动非零拟合

动态数据(例如刷新网页时的新数据)是我们不能使用恒定域范围的典型情况。在另一个图表中 on VEGA editor两者 scale.zero (颜色和尺寸)设置为 false ,导致自动缩放范围调整:
    "size": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "mean",
"scale": {"zero": false }
},
"color": {
"field": "n_pmin",
"type": "quantitative",
"aggregate": "mean",
"scale": {"scheme": "bluegreen", "zero": false}
}

关于vega-lite - 如何在穿孔卡片中使用所有圆圈大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61646358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com