Adding a 'domainMax' property to an existing Vega visualisation using Vincent

297 views Asked by At

I'm creating a StackedBar viz using Vincent in Python. Data is from a pandas dataframe, with each column representing a percentage and each row sums to 100%

Vincent / Vega is trying to be helpful and adding a buffer to the Y axis so that it maxes out at 110 (%) when I want to be 100.

The property I need to add is 'domainMax' in the grammar for the Y scale, but I can't work out how to use Vincent's PropertySet or similar commands to add this in after importing the Pandas dataframe.

Here's an example of the data with domainMax added in manually, can anyone advise on how to do this in 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  
    }

[...]

1

There are 1 answers

2
Phil Sheard On

Problem was that Vincent and Vega using slightly different naming conventions, and this wasn't explicitly in the Vincent docs.

Vega has "domainMax" on their docs [1] whereas the Vincent property you need to target is "domain_max", found within Scales.py [2]

So the solution was: chart.scales[ref].domain_max = value

In practice:

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