Search code examples
juliamakie.jl

Displaying figures as vector graphics with Makie in Julia


I am using the Makie library for visualization in Julia. Whenever I display my figure (by running display(fig)), it opens an image viewer with a png image. Can I somehow get this to instead show me a vector image? Or is there an alternative to display which can do this? (Previously I have been using PyPlot which does this by default)

I know I can save the figure as pdf/svg and open it separately, but is kind of tedious to do every time I want to inspect my figure.

EDIT: I am using Cairo Makie backend. It can create a pdf/svg file when saving, but does not do so, when just (pre)viewing the figure.

EDIT2: I am running julia from terminal, by running julia, and then manually including and running my code into the live julia session.

I tried looking into the definition of display function in the source code of CairoMakie; if I add the configuration stuff (such as type = "pdf", px_per_unit = 10), it is indeed in the configuration, but the type option does not change anything, presumably because (from terminal) I am not inlining the figure. (Not sure what inline actually means in this context, that is what it is called in the code...) The px_per_unit option works though.


Solution

  • If you are using CairoMakie, you should be able to swich from png to svg if your system's software (your IDE, eg VS Code, etc) is already set up to be able to display svg. You would call

    CairoMakie.activate!(type = "svg")

    See also https://docs.makie.org/v0.21/explanations/backends/cairomakie.

    If you are not using a graphics-enabled IDE and your OS does not have command line support for SVG file display, you can use ElectronDisplay.jl as mentioned here: https://discourse.julialang.org/t/displaying-an-svg-without-a-notebook/82684

    So, you ]add ElectronDisplay to Julia's packages, then add

    using ElectronDisplay
    

    to the program.