Altair – A declarative statistical visualization library for Python
github.com
github.com
Most of the commercial and open source solutions including Tableau, Apache Superset, Metabase were very complicated to provide a seamless integrated dashboard with our Single Page Application using the same authenticaton and authorization layer. Most of these solutions recommend using iFrame. With altair we could directly generate the target vega-lite json for our web component and it work seamless.
Also for some static reports we could generate output in other formats from altair directly. Altair being in Python (Apache Superset was a big contender), it was easy enough to integrate into our backend as one of the analytics services provider. Given vega-lite and vega grammar is standardized, we are exploring to build real-time dashboard analytics application for large multi-screen display in a control room kind of an environment.
Before altair our backend was generating data directly consumed by chartjs web component.
[1] https://altair-viz.github.io/user_guide/custom_renderers.htm...
In general with FastAPI you can integrate altair to generate your vega-lite json as a response to an API request taking care of authentication and authorization in FastAPI (either with JWT token or other schemes like oauth2).
However I didn't get around to learning the principles to use it regularly. And I fear if you have a certain chart in your head with some special stuff you end up tinkering around eventually get a lot of code.
Don't the examples in the README provide a good enough intro?
If you are familiar with matplotlib and ggplot, you'd have a good idea how to reproduce those examples in those frameworks. If you are not familiar with them, then what good is the comparison?
def foo(a, b, **kwargs):
"""
Refer to `bar` for the full list of allowed kwargs.
"""
...
i don't mind the former, but the latter always feels annoying. iirc matplotlib severely suffers from thisIt looks like with altair you can only "add" things that are already a method on your altair object. How does 3rd party geoms and similar work?
Their write up on the data format is here: https://altair-viz.github.io/user_guide/data.html#long-form-...
One would first make a relevant data transform and then send it to whatever plotting library. I suspect anything further would limit the flexibility of the plotting library. To make sure I have minimal pain with data transforms, I first store/transform data exactly like I would in a real transactional database. Beyond that it just becomes a matter a joins and filters/projections.
If you are missing ggplot2 in Python, I’d say look here first.
Anyway, this seems cool.
And it gets worse because it gets new APIs with almost identical names to the previous ones, without a proper guide for when to chose which API.
And yes it's just so ugly by default.
How is this an addendum, rather than the main point? I will always take a flexible library that allows me to "get the job done" over a declarative framework that will do something similar to—but not exactly—what I need.
GGplot2 is _very_ nice to use and an incredible library...as long as you want to do something the package author approves of. Want to change some behavior about how bins are generated because the default behavior lies? Too bad.
Matplotlib is ugly, but it doesn't make decisions for you, and once you understand it, you can do anything with it.
Every time I use matplotlib, I have to look up how to remove the border on my graph, make things slightly transparent, etc. The default colour palette isn't colourblind friendly, so the other day I spent half an hour trying to set up a more accessible one. I had to create / fetch 3 objects, their names being something like ScalarMap, Normalize and cmap. Why do I need to understand the relationship between these 3 objects when all I want to do is switch from one palette to another?
Meanwhile, it's so flexible as to be annoying for a non-expert. I often encounter matplotlib answers on StackOverflow about things that I would expect to "just work", but that actually require 20 lines of code to solve, written by someone who appears to be deeply familiar with the internals of the library.
Note: I'm not saying that a declarative approach solves these things.
Matplotlib makes everything complex.
Declarative systems always seem to feel good (SQL and React come to mind)
Vega-lite is the underlying standard (A Grammar of Interactive Graphics ): https://vega.github.io/vega-lite/
I used altair in a hackathon interview and got the job: https://github.com/DustinAlandzes/drchrono-hackathon/blob/ma...
sadly not hosted
Altair isn’t quite that, but it’s the closest I’ve seen. I wish python had ggplot2 with its html widgets, but this will do.
I’ve been really impressed with the browser compatibility in that I’ve yet to find a bug despite lots of weird mobile users. That and the team adds functionality quickly so almost as soon as I’m annoyed at not ability to add captions, it’s made available.
I'll shamelessly plug Plotly Express (https://plotly.express/) here as something that works in a similar way, i.e. generates JSON figure descriptions rendered in Javascript, with an even more minimal API, that now accepts both long and wide data :)
https://altair-viz.github.io/gallery/scatter_linked_table.ht...
The place where you start to run into problems is if you want to filter the table based on interactions with the chart. If you're going to use dropdowns and checkboxes to filter the dataframe and the chart then you have a lot of good options.
So basically use ipwidgets to create the checkmarks/radio/dropdowns. Then hook the database up to altair. I'll play tommorow with altair and ipywidgets and see how I can cook this up.
"filter the table based on interactions with the chart" For me all I'd need is a the corresponding datapoint selected to highlight the row.
Personally I would look into plotly / dash for something with interactivity.
https://altair-viz.github.io/gallery/interactive_legend.html
https://altair-viz.github.io/user_guide/interactions.html#se...
Some of those other options look pretty compelling too I think it's definitely time for something to replace Matplotlib as the go-to for python plotting.