Debugging Altair

The preceding example works, but in the real world, any development is a process of trial and error. Debugging might be daunting with the Vega stack due to the layered nature of the product (Altair converts charts into Vega-Lite, Vega-Lite converts them into Vega, and the Vega engine works in JavaScript) and because we're working in this non-Pythonic world.

As with all code in general, the process is to isolate different parts and layers of the application to identify the root of the problem. Identification will give you ideas on how to solve the problem and work around it. Unfortunately, we can't just split parts of the specification. So, what can we do if your chart does not work as intended?

Despite all of the issues, the stack has one advantage in that regard: everything lives upto the specifications, which are human-readable and, generally speaking, human-writable. The simplest way to debug is to open a chart in the Vega editor (for example, via the triple-dot button) and start tinkering around. Here is a screenshot of the same dashboard in the editor:

Sometimes, what you want is not available via the Vega-Lite specificationsthen, in the same editor, you can convert them into Vega and continue editing there. Once the issue is resolved, you have two options: one is to adjust your Altair code accordingly— often, it is easy. Alternatively, you can store the specifications separately and just use them via Altair or the Vega app.

There are some other options, too. For example, the Voyager tool, also free and hosted on the web, tries to help you to pick the right visualization for specific data, while Lira (also hosted and free) is meant as drag-n-drop software, based on Vega. Both could help you at the start of your project, and you can always juggle your specifications between the tools, according to your current needs. All of the afore mentioned toolsand then somecan be found on Vega's official web page: https://vega.github.io/.

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

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