In general, passing None
in Python/Altair will result in null
in JSON/vega. For example, when hiding a legend ("legend": null
in Vega-Lite) you can use legend=None
in Altair, as mentioned in Adjusting the Legend.
In the case of aggregates, however, that will not work: according to the Vega-Lite schema, null
is not a valid argument for aggregate
, and so attempting this in Altair will result in a SchemaValidationError
.
If for some reason you really want to produce this invalid specification, you can do so by passing validate=False
to alt.Chart.to_json
:
import altair as alt
chart = alt.Chart().mark_bar(tooltip=True).encode(
x=alt.X('Creative Type:N', aggregate=None),
y=alt.Y('Creative Type:N', aggregate='count')
)
print(chart.to_json(validate=False))
# {
# "$schema": "https://vega.github.io/schema/vega-lite/v4.8.1.json",
# "config": {
# "view": {
# "continuousHeight": 300,
# "continuousWidth": 400
# }
# },
# "encoding": {
# "x": {
# "aggregate": null,
# "field": "Creative Type",
# "type": "nominal"
# },
# "y": {
# "aggregate": "count",
# "field": "Creative Type",
# "type": "nominal"
# }
# },
# "mark": {
# "tooltip": true,
# "type": "bar"
# }
# }