我正在使用Python中的Vincent创建StackedBar viz。数据来自大熊猫数据框,每列代表一个百分比,每行总和为100%
Vincent / Vega正在尝试提供帮助,并在Y轴上添加一个缓冲区,以便在我想要100时达到最大值110(%)。
我需要添加的属性是Y scale的语法中的'domainMax',但我无法弄清楚如何使用Vincent的PropertySet或类似的命令在导入Pandas数据帧后添加它。
以下是手动添加domainMax的数据示例,任何人都可以建议如何在Python中执行此操作
"scales": [
{
"domain": {
"data": "table",
"field": "data.idx"
},
"name": "x",
"range": "width",
"type": "ordinal"
},
{
"domain": {
"data": "stats",
"field": "sum"
},
"name": "y",
"nice": true,
"range": "height",
"type": "linear",
"domainMax": 100
}
[...]
答案 0 :(得分:2)
问题在于Vincent和Vega使用的命名约定略有不同,而Vincent docs中没有明确说明这一点。
Vega在他们的文档上有“domainMax”[1],而你需要定位的Vincent属性是“domain_max”,在Scales.py中找到[2]
所以解决方案是:chart.scales[ref].domain_max = value
在实践中:
chart = vincent.StackedBar(dataframe)
chart.scales[1].domain_max = 100
chart.display()
[1] https://github.com/trifacta/vega/wiki/Scales
[2] https://github.com/wrobstory/vincent/blob/master/vincent/scales.py#L77