TLDR: Lack of a python-package that outputs typst-lilaq code for the visualization in typst from Matplotlib in Python.
I’ve started using typst over the holidays, and since I am currently working on my PhD thesis, I came up with the idea of what is missing for me to write it in typst. The only thing that came up to me was an equivalent of tikzplotlib (now matplot2tikz) for a workflow where the data processing takes place in Python and a readable .typ-file is getting created for the writing part in typst.
Yes, there exists mpl-typst but that was developed before lilaq, so the output code I get for my use cases is not very clear to understand and modify. And yes, there is lilaq where you can do the data visualization instead of using Python, but that is comparable to PGFPlots in LaTeX with the obvious benefits. Feel free to do data visualization directly in lilaq but in my mind, getting lilaq-like typst code directly from Python (where most people do data analysis) would reduce the barrier of switching from LaTeX for people like myself.
So just to get this clear: I am not working on such a package right now; I just had the idea. If someone thinks that would be a cool side project, feel free to do it. Maybe I’ll find some time to work on it, but don’t expect anything more than a pre-alpha written by a chemical engineer that just works. That aside, I don’t mean to replicate the matplotlib style in lilaq, only what has been set in Python explicitly should find its way into the code.
If you see this differently or have further ideas, you know where to put them.
I’ve created several reports involving Python and CeTZ/Lilaq, some of them are fully automated. I’m not sure how much it’s possible, but I feel like when your goal is to make high-quality everything, you just can’t write a less flexible interface to achieve what you need. If the API is 1-to-1, then maybe. But it’s already not fast to tweak Lilaq to make everything look good, and now you need to use a wrapper API to try and achieve the same thing? idk
The general idea is to output some data in JSON from Python, and then use those files to fill in blanks/data in the document. You can try and use Prequery, though for my setup it’s not very convenient or worth the complication. But I did use it at least once for some of the fully automated reports.
Lately, since computations allow, I created 2 fully automated reports fully in Typst, so everything is in one file, and all I need to change is the input data, i.e., a single line. The figures look awesome.
But I’m also not/no longer an all-Python geek, so I don’t need everything to have a Python interface.
I created pretty much exactly the package you are looking for to create the plots my own PhD thesis. The idea was to have a middleground between mpl-typst and lilaq. The idea is to generate a .typ file that conserves the structure of the matplotlib figure, which allows later editing with reasonable effort. A few examples for the translation from Python to Typst:
suplots or gridspec in Python → use a grid (simple rescaling of axes in Typst)
lines, errorbars, etc… → curves and shapes (the data is saved in a json file)
legend → use the shared styles from the lines etc…
Instead of using the custom backends in matplotlib that just dump everything as a line, a shape or some text (there might be a fourth one here, not sure), I am reading all the information about the plot starting from the figure object. While there is still some information missing compared to the original methods, it is very close to the structure you use while creating the plot.
Disclaimer: The package is far from complete/stable. I implemented only the stuff I needed for my own thesis and definitely cut some corners towards the end to just be done with it. That said, I am very happy with the results and I would definitely put in the same effort again to build this package. Let me add an example and a readme file before setting the repository to public. I should have time to get this done by the end of the weekend.