Storing the Altair chart

One simple way to export your chart as a raster or vector image is via the triple-dot button. But you can also do this programmatically if you need to. First, we need to store the composite chart as an object. Next, we just execute the save; the method-specific type of export will be inferred from the file type:

chart = basemap + points
chart.save('chart.png') # or 'chart.svg' for vector

Programmatic export for both png and svg requires the Selenium package and either Google Chrome or Mozilla Firefox browser, plus a corresponding driver to be installed—check the documentation via https://altair-viz.github.io/user_guide/saving_charts.html#png-and-svg-format.

An alternative to this is to store a raw specification. For that, just change the path to chart.vl.json. This specification can be later used by another instance of a Vega-Lite application. JupyterLab will render this specification automatically, and there is a plugin for VS Code that will do the same.

Finally, the simplest way to publish your chart on the web is to export it as an HTML application (in fact, it just stores exactly the same HTML app every time, just with a different JSON specification):

chart.to_html('chart.html')

Go ahead and open this HTML in your browser—it should show up and behave (including all of the interactions) exactly the same way it did in the Notebook! Now, the only thing left to do is to move this file somewhere online, for example, onto an Amazon S3 bucket or similar service.

In this section, we just scratched the surface of what is possible with altair, but no worries! We'll go for a deeper round in Chapter 17, Let's Build a Dashboard, when we'll build an interactive data dashboard.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.162.65