3 ms·
Working as a data scientist, I have exclusively used Altair since I joined my company in 2021. Every one of my coworkers uses Matplotlib. Two people said some
by ryan-duve 3y ago
Working as a data scientist, I have exclusively used Altair since I joined my company in 2021. Every one of my coworkers uses Matplotlib. Two people said something like "Oh, you're using that library that's supposed to be better and probably is, but I just don't want to relearn everything for plotting" but nobody else has even shown interest, let alone taken the plunge.
If 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_<plot_type>.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")`.
- RobinL 3y agoTo save to an image in Altair, it's just chart.save("myimage.png"). This works much better since version 5 (the syntax is the same but the dependencies are less fiddly)
- jerpint 3y agoI use seaborn to plot directly with pandas, does Altair have any extra advantages? Or is it a similar style?
- RobinL 3y agoI wrote an article a while back about why I think it's the best default choice for vis in Python: https://www.robinlinacre.com/backing_vega_lite/ https://www.robinlinacre.com/backing_vega_lite/
- jmmease 3y agoImage export before Altair 5 was a bit complicated because it required either selenium plus a system web browser, or a node.js installation. In Altair 5, we switched to using vl-convert for image export, which is just a regular Python wheel with no external dependencies. So now, `chart.save("file.png")` should be just as easy to use as matplotlib's savefig! (Disclaimer: I'm a Vega-Altair maintainer and the author of vl-convert)