KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Showing a figure with a `Graphics` entry with a relative path fails #283

Open KristofferC opened 2 years ago

KristofferC commented 2 years ago

Reported from slack

using PGFPlotsX
using KernelDensity
using ColorSchemes

data = (rand(1000), rand(1000))

k = kde(data)

npoints = 400
es = map(extrema, data)
rgs = map(e -> range(e...; length=npoints), es)
res = pdf(k, rgs...)

res = reverse(transpose(res), dims = 1)

cs = get(ColorSchemes.jet1, res, (minimum(res), maximum(res)))

PNGFiles.save("img.png", cs)

figure = Axis(
    PGFPlotsX.Options(
        :enlargelimits => "false",
        :axis_on_top => nothing,
    ),
    Plot(
        PGFPlotsX.Graphics(
            PGFPlotsX.Options(
                :xmin => first(k.x),
                :xmax => last(k.x),
                :ymin => first(k.y),
                :ymax => last(k.y),
            ),
            "img.png"
        )
    )
)

fails to show the figure because I guess we put the .tex file in a temp folder. I think we need to put it in the same folder.

rs7q5 commented 2 years ago

Ran into this issue today as well. You can solve it by defining graphicspath or by providing it the absolute path. But if on Windows, you have to use raw"{filename} because of the \\ present in a folder name. Would be great if one could provide the folder separately and then the filename. I haven't figured out a way to get the string literal to accept a variable folder name using $ like normal.