Vega-Altair: Declarative Visualization in Python
altair-viz.github.io
Vega-Altair: Declarative Visualization in Python
1–10 of 44 posts
Re: Vega-Altair: Declarative Visualization in Python
#2Sidenote: I like Altair and think it's a good development, despite rendering being performed client side.
This said, the claim here is tiring when it's used everywhere. Having spent significant time with Altair, I'd argue it might have tighter code but the documentation can be obscure. I haven't found it to make things easier from a developer perspective, but rather it does solve the use case that you are working in Python and need to have the client render a figure without callbacks (things like raw html dumps and similar).
Re: Vega-Altair: Declarative Visualization in Python
#3 # Vega-Altair
alt.Chart(source).mark_line().encode(
x='x',
y='f(x)'
)
# Pyplot
plt.plot(source)
plt.xlabel('x')
plt.ylabel('f(x)')
[1]: https://matplotlib.org/stable/tutorials/pyplot.htmlRe: Vega-Altair: Declarative Visualization in Python
#4Re: Vega-Altair: Declarative Visualization in Python
#5If you need to learn a plotting library and you already work in Pandas, I recommend choosing Altair to learn. It's a natural extension to pd.DataFrame and the only magical incantation to learn is
alt.Chart(df).mark_.encode(x=df["col"], y=df["other_col"])
I find this significantly easier to work with than Matplotlib, where the same things can be done in several ways with subplots, plt.figure(), df.plot(), and maybe others?My only complaint with the library is that outputting to an image file feels weirdly complicated. I often resort to making HTML files and taking a screenshot if I don't want to take the time to look up all the steps equivalent to `.savefig("file.png")`.
Re: Vega-Altair: Declarative Visualization in Python
#6Are there non-declarative chart visualization libraries? I’ve always used matplotlib.pyplot [1] and while it doesn’t market itself as "declarative", I don’t see much difference: # Vega-Altair alt.Chart(source).mark_line().encode( x='x', y='f(x)' ) # Pyplot plt.plot(source) plt.xlabel('x') plt.ylabel('f(x)') [1]: https://matplotlib.org/stable/tutorials/pyplot.html
Take a faceted plot like this scatter matrix [1] and try to plot it in matplotlib. You would need to set up the grid using subplots, then define the combinations you want and finally write logic to fill each subplot. The vega/altair code is much more declarative. You just tell it what needs to be in the rows/columns and vega/altair takes care of the rest.
[1]: https://altair-viz.github.io/gallery/scatter_matrix.html
Re: Vega-Altair: Declarative Visualization in Python
#7Every data scientist endeavors to make an impact with their analysis, and ultimately that is typically tied to some kind of visualization. There needs to be a way to a) build the visualization you want and b) get it out there to people who would find it useful.
Just plotting in matplotlib means that you must either export as a PNG (ew) or provide the analysis itself to users/decision makers. PNGs are terrible because you completely lose interactivity. Providing the analysis means figuring out deployment of your python environment, which is possible but just causes another step between analysis and decision made on the analysis.
Altair and the vega-lite grammar of visualizations provides an interoperable and data centric way to build visualizations. It is extremely flexible when building visualizations and I find it very intuitive when it comes to complex plots. They can also be easily embedded into any webpage after being exported using the vega-lite spec, just include the vega-lite script in the html page. Can even be used with in dashboarding tools like Spotfire (I assume also with things like PowerBI although I haven't done it).
Imo no real reason to use matplotlib as a data scientist lest you seriously limit the future impact of your work
Re: Vega-Altair: Declarative Visualization in Python
#8[1] https://link.springer.com/book/10.1007/0-387-28695-0
[2] https://stackoverflow.com/questions/4892368/implementations-...
Re: Vega-Altair: Declarative Visualization in Python
#9Are there non-declarative chart visualization libraries? I’ve always used matplotlib.pyplot [1] and while it doesn’t market itself as "declarative", I don’t see much difference: # Vega-Altair alt.Chart(source).mark_line().encode( x='x', y='f(x)' ) # Pyplot plt.plot(source) plt.xlabel('x') plt.ylabel('f(x)') [1]: https://matplotlib.org/stable/tutorials/pyplot.html
Re: Vega-Altair: Declarative Visualization in Python
#10I'm using Plotly more lately, for 2 reasons - chart have very good interactivity by default and I'm also a Dash user - so it comes in naturally.
But I believe Altair is excellent for exploration - simple charts are very simple to create, and it's not complicated to create a complex exploration dashboard - with all charts linked between them - so you can select a subset of data on one chart, and it automatically updates the others. Highly recommend at least exploring it !