rsmf icon indicating copy to clipboard operation
rsmf copied to clipboard

Altair support

Open jedbrown opened this issue 3 years ago • 5 comments

Altair is a 2D plotting library based on grammar of graphics (like R's ggplot2), typically producing Vega-Lite output (for interactive web output). Static figures can also be saved as PDF or SVG using altair_saver. If you're willing to abstract matplotlib in rsmf, it seems it would be feasible to also support Altair, which would enable use of the same plotting platform for interactive figures in HTML talks as well as PDF figures in static papers.

jedbrown avatar Sep 20 '20 20:09 jedbrown

I agree that it seems feasible. But I first have to understand a few things:

  • The purpose of rsmf is to format figures for use with LaTeX. To obtain the same optics, the pgf backend of matplotlib is used which is essentially rendering the figure through LaTeX, ensuring coherent optics. Does Altair have a similar, LaTeX-compatible backend? If not, ensuring the correct fonts are used will be super hackish.
  • HTML talks are somewhat out of scope for rsmf, as it is built to pull the information of how to setup the PGF backend from TeX. So I don't see how rsmf would bring a benefit there?

johannesjmeyer avatar Sep 21 '20 07:09 johannesjmeyer

There is no analog to matplotlib's pgf backend. @jakevdp may have thoughts on how difficult it would be to teach Altair to save using PGF or similar.

I didn't mean to imply that rsmf would be used for HTML plots. Rather, that a single visualization would be created using Altair to be used in talks/websites, and use rsmf to help make the fonts paper-friendly. My present workflow has been to either live with font mismatch or to recreate a similar figure using matplotlib, but that requires remembering (and teaching or expecting students to learn) two disparate plotting interfaces.

jedbrown avatar Sep 21 '20 13:09 jedbrown

The vega-cli package has methods to save vega/vega-lite charts to png, svg, and pdf. If none of those are suitable for the purposes here, that package would be the place to implement other formats.

jakevdp avatar Sep 21 '20 15:09 jakevdp

It seems like all the existing outputs in vega-cli go through Vega's renderHeadless() so we'd be looking for JavaScript libraries that output pgf/latex. My search didn't turn up much, but I'm very unfamiliar with the JS ecosystem.

jedbrown avatar Sep 21 '20 15:09 jedbrown

Okay, but from this vantage point it looks like supporting vega would first require some changes on the vega side. I think the important features to add to rsmf before this can be addressed are additional journal venues. So I'd postpone a possible vega integration.

johannesjmeyer avatar Sep 22 '20 10:09 johannesjmeyer