I’m using Julia on my phone and so CairoMakie.jl can’t display plots directly, but it does save it to a temp directory. But this directory is very inconvenient since it’s buried under two VM layers (Android->termux->Ubuntu->Julia)
So is there a way to change the default tmp directory?
julia> lines(0..0.01,x->sin(x^-2))
┌ Warning: Can't find a way to open a browser, open file:////tmp/jl_QLdeRR/display.png manually!
└ @ CairoMakie ~/.julia/packages/CairoMakie/wKKMp/src/display.jl:31
I’ve found a solution.
The function that saves the temp file is ~/.julia/packages/CairoMakie/wKKMp/src/display.jl
we can edit line 41 and replace mktempdir()
with the new directory, you can even use pwd()
to make it the current working directory.
Next, precompile CairoMakie by running
]precompile CairoMakie
And restart Julia.
On my case the modified function looks like this:
function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false)
path = joinpath("/root/Pictures", "display.png")
Makie.push_screen!(scene, screen)
cairo_draw(screen, scene)
Cairo.write_to_png(screen.surface, path)
if screen.visible
openurl("file:///" * path)
end
return screen
end
I’ve made a soft link to the Pictures folder in my Ubuntu VM home directory for convenience.
This will of course be undone when the package gets updated.
If anyone has a better solution I’d love to hear it
mktempdir
uses tempdir
to choose the default parent of the temporary directory, so for example you can do
withenv("TEMP" => pwd()) do
# do something...
end
This isn’t perhaps exactly what you asked because you’re only affecting the parent of the temporary directory, but you don’t have to edit in place the source code of the package, which is a bad idea.
3 Likes