Altair: How Altair interprets the information and generates the display?

Created on 16 May 2019  路  2Comments  路  Source: altair-viz/altair

Hi. I started using the library and found it very interesting.

I am interested in knowing how Altair works as a library when it is executed on a jupyter notebook. I wonder if it is possible to explain to me how is the mechanism with which it is interpreted by Vega-Lite, but I wanted to know how this result is generated from behind and finally how this result is delivered to the notebook.

Thanks.

question

All 2 comments

Sure: Altair rendering works via JupyterLab's mimebundle rendering. Chart objects implement a method called _repr_mimebundle_, which returns a dictionary of possible chart representations. One of these has a mimetype application/vnd.vegalite.v3+json, and if your frontend has an extension installed that knows how to handle this mimetype, it will load the necessary resources to display the chart.

This is how it works in JupyterLab; Jupyter notebook is a bit different.

There's some more info on this sort of thing scattered among the following places:

An example of the mimebundle rendering is below. If you run this code in JupyterLab, it will show the HTML. If you run it in a frontend that doesn't support HTML (such as the IPython terminal), it will show the plain text.

class Foo(object):
   def _repr_mimebundle_(self, include=None, exclude=None):
       return {
           'text/html': '<b>HTML Output</b>',
           'text/plain': 'Plain output'
       }

Foo()

Altair's vega-lite mimetype output is similar: what is shown for a chart depends on what your frontend knows how to display.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakevdp picture jakevdp  路  36Comments

pagpires picture pagpires  路  21Comments

jakevdp picture jakevdp  路  48Comments

jakevdp picture jakevdp  路  23Comments

HalukaMB picture HalukaMB  路  31Comments