【问题标题】:Adding a 'domainMax' property to an existing Vega visualisation using Vincent使用 Vincent 向现有 Vega 可视化添加“domainMax”属性
【发布时间】:2013-12-30 04:02:34
【问题描述】:

我正在使用 Python 中的 Vincent 创建 StackedBar 可视化项。数据来自 pandas 数据框,每列代表一个百分比,每行总和为 100%

Vincent / Vega 试图提供帮助,并在 Y 轴上添加一个缓冲区,以便当我想达到 100 时它会在 110 (%) 时达到最大值。

我需要添加的属性是 Y 刻度语法中的“domainMax”,但在导入 Pandas 数据框后,我不知道如何使用 Vincent 的 PropertySet 或类似命令添加它。

这是手动添加 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  
    }

[...]

【问题讨论】:

    标签: python pandas vega vincent


    【解决方案1】:

    问题是文森特和 Vega 使用稍微不同的命名约定,这在文森特文档中没有明确说明。

    Vega 在其文档 [1] 中有“domainMax”,而您需要定位的 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

    【讨论】:

    • 我应该在 Vincent 文档中更明确地说明这一点 - Vega 中所有骆驼式大小写的东西都用下划线进行了 Python 化。此外,任何在 Python 中作为保留字的 Vega 参数都带有下划线。
    • 感谢@RobStory 的评论-感谢您的清晰。如果有什么我可以支持的,请告诉我,我认为这是一个很棒的图书馆。
    猜你喜欢
    • 1970-01-01
    • 2019-04-18
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 2018-10-23
    • 1970-01-01
    • 2015-07-27
    相关资源
    最近更新 更多