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.
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.
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.