2. Extract From Altair.ipynb

Extracting vega lite from altair

Let's create an example altair chart:

In [1]:
import altair as alt
from altair.expr import datum

from vega_datasets import data
pop = data.population.url

alt.renderers.enable('default')
c = alt.Chart(pop).mark_bar().encode(
    x=alt.X('sum(people):Q', axis=alt.Axis(title='population')),
    y='age:O'
).properties(
    height=300,
    width=300
).transform_filter(
    datum.year == 2000
)
c
Out[1]:

Now let's look at the json representation of the vega lite:

In [2]:
alt.renderers.enable('json')
c
Out[2]:
<VegaLite 2 object>

If you see this message, it means the renderer has not been properly enabled
for the frontend that you are using. For more information, see
https://altair-viz.github.io/user_guide/troubleshooting.html

Let's now render this but instead extract transformations out to the top level of the vega lite spec:

In [3]:
import omnisci_renderer
alt.renderers.enable('extract-json')
c
C:\Anaconda3\lib\site-packages\ibis\sql\postgres\compiler.py:223: UserWarning: locale specific date formats (%c, %x, %X) are not yet implemented for Windows
  'for %s' % platform.system()
<IPython.core.display.JSON object>
Out[3]:

Now we see transformations at the top here.

We can also plot this transformed chart, which looks the same:

In [4]:
alt.renderers.enable('extract')
c
Out[4]: