Vega Altair visualization notes
Config
Top-Level Chart Configuration — Vega-Altair 6.3.0.post4+gb2ca919d documentation
All together with .properties on the Chart object itsel:
alt.Chart().encode().properties().top_level_configuration_item()
Etc
-
- Channels (x,y etc.): Channels — Vega-Altair
- Encoding data types:
- Shorthand syntax1
- Q: quantitative: ‘a continuous real-valued quantity’
- Discrete/categorical:
- O: ordinal (=sortable)
- N: nominal (=not sortable)
- T: temporal, G: geojson
- Shorthand syntax1
-
Faceted charts (=multiple side-by-side):
- Layered & Multi-View Charts — Vega-Altair 6.3.0.post4+gb2ca919d documentation
- Simple:
.encode(x=..,y=..,column=xxx,row=yyy
-
Sorting
- Rendering multiple altair charts in a single cell of a jupyter notebook
graph[0].display() graph[1].display() - Legends
- Disable:
alt.Color().legend(None)(! not inside Color()!) - Multiple legends
- Displaying Two Different Legends in hconcat Chart Using Altair - GeeksforGeeks
- Scale & Guide Resolution — Vega-Altair 6.3.0.post4+gb2ca919d documentation
.encode( alt.X("variable"), alt.Y("count()"), alt.Color("value:N", legend=alt.Legend(title="x")), # TIL alt.Scale(scheme='blues') # make colors different too ) #... alt.vconcat(*charts).resolve_scale(color="independent") - API: altair.Legend
- Disable:
- New lines to labels
- passing a list of strings instead of string makes them newlines[^2]
labelExpr="replace(datum.label,'_','\\n')"doesn’t seem to work for newlines- Customizing Visualizations — Vega-Altair 6.3.0.post4+gb2ca919d documentation
- takes us to d3-format | D3 by Observable for formatting a la python,
:.2fonly for numbers
- takes us to d3-format | D3 by Observable for formatting a la python,
- more on this: Dynamic Behaviors with Parameters | Vega-Lite
- Customizing Visualizations — Vega-Altair 6.3.0.post4+gb2ca919d documentation
Composing
- Rule — Vega-Altair 6.3.0.post4+gb2ca919d documentation
- draw lines and ranges and candlesticks with y2/x2
- Line Chart with Datum — Vega-Altair 6.3.0.post4+gb2ca919d documentation to highlight values
References
- Colors are valid CSS color names: [
CSS type - CSS | MDN
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus