Altair: Is there any method to export Chart spec without data?

Created on 10 Sep 2018  路  4Comments  路  Source: altair-viz/altair

Hi, I am new to altair.

Is there any method to export Chart spec without data?

Now, I write the below and do this, but it is pain.

d=chart.to_dict()
d.pop("datasets")

So I want to do this with one method, like chart.spec.

Most helpful comment

Thinking about it a bit, I could see how this would be a useful feature to have. We could probably implement it as a custom data transformer, though it might involve some subtle issues with nested datasets within compound charts.

All 4 comments

You can export a chart without data if you don't supply any data to the chart in the first place. For example:

>>> chart = alt.Chart().mark_point().encode(x='column:Q')
>>> chart.to_dict(validate=False)
{'$schema': 'https://vega.github.io/schema/vega-lite/v2.6.0.json',
 'config': {'view': {'height': 300, 'width': 400}},
 'encoding': {'x': {'field': 'column', 'type': 'quantitative'}},
 'mark': 'point'}

Note that we need validate=False because according to the schema, a vega-lite spec is not valid without data specified.

Thank you for your kind reply!

I would like a method to export spec conveniently, even after plotting with chart, so that save as a template.

No, there's no way to export charts without data short of manually removing the data before export.

Thinking about it a bit, I could see how this would be a useful feature to have. We could probably implement it as a custom data transformer, though it might involve some subtle issues with nested datasets within compound charts.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fischcheng picture fischcheng  路  4Comments

HalukaMB picture HalukaMB  路  3Comments

zanarmstrong picture zanarmstrong  路  4Comments

bmcfee picture bmcfee  路  3Comments

nielsmde picture nielsmde  路  4Comments