Re:Vega-Altair: Declarative Visualization in Python
by RobinL on Monday February 26, 2024 @02:02AM
(#39508329)
To 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)
Re:Vega-Altair: Declarative Visualization in Python
by jerpint on Monday February 26, 2024 @07:12AM
(#39510374)
I use seaborn to plot directly with pandas, does Altair have any extra advantages? Or is it a similar style?
Re:Vega-Altair: Declarative Visualization in Python
by RobinL on Monday February 26, 2024 @11:16AM
(#39513033)
I 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/
Re:Vega-Altair: Declarative Visualization in Python
by jmmease on Monday February 26, 2024 @10:33AM
(#39512433)
Image 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)
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
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")`.