LaTeX Support for Interactive Plotting

Just jumped into Julia from MATLAB so I’ve been spoiled with nice plotting experience, but I want to transition workflows into Julia for academic research.

For plotting, I noticed that using LaTeXStrings works well for creating static plots, but when I try to do interactive plots (panning, cropping, zooming, etc) using various backends (PlotLy, Plotlygs) the latex formatting falls off.

I’ve seen other posts regarding this, but they are dated (~2020). Does any know if a solution or a workout has been established for this shorftall of Julia?

I am old-fashioned and use GitHub - JuliaPy/PyPlot.jl: Plotting for Julia based on matplotlib.pyplot or GitHub - aenarete/ControlPlots.jl: Create plots that can be saved and edited with Julia .

Makie does interactive plots with LaTeXStrings but like in most other packages it’s not real LaTeX but an approximation through MathTeXEngine.jl

On the other hand, if it was real LaTeX it wouldn’t be fast enough for interactivity anyway.

1 Like

Thank you all! I understand that my request may be unreasonable to ask Julia to do exactly what I am used to in other languages.

What are you missing? Welcome to Makie! | Makie and ControlPlots.jl both support LaTeX, zooming and panning, Makie being very powerful, my ControlPlots package being very simple and easy to use.

Thanks for replying. Again, I acknowledge this may be unreasonably particular, but I was looking for exact LaTeX formatting with dynamic plotting interface.

I’ve uploaded an example of plot font froM Control Plots vs MATLAB’s LaTeX rendering:
Screenshot 2024-07-28 at 15.20.28

here’s Control Plot’s. Again, I’m not trying to complain about anything - just wondering of what are the capabilities and limitations of Julia compared to what I’m used to.
Screenshot 2024-07-28 at 15.20.33

Can you share the LaTeX source code?

Sure! From MATLAB:

xlabel("$\hat{P}$", "Interpreter", "latex", "FontSize", 20);

where that is attached to whatever plot you want. Here’s what I tried in Julia:

using ControlPlots, LaTeXStrings
plot(X, Y, xlabel=L"\hat{P}", fig="basic")

Did you try to export the figure in pdf format? Looks much better to me.
P

And you can also get high quality screen rendering if you add this:

rcParams = plt.PyDict(plt.matplotlib."rcParams")
rcParams["text.usetex"] = true

to the beginning of your script, but that requires that you have LaTeX installed locally on your machine.

Thanks for checking! I noticed that, in fact, using Plots.jl renders the PDF of exact LaTeX (or at least, close enough to me). However it’s not quite the exact same font for the dynamic/interactive plotting environment.

As @jules pointed out, the exact LaTeX for match may be too much for dynamic plot interaction. This by far not a deal-breaker for me and I know it’s probably falls under the “splitting hairs” category. But just something I’ve noticed and wondering if there was an exact.

Would I spend all the money for MATLAB’s license just for a font rendering? No.

All possible for free, see update of my last post. Just a little bit more hassle to install.