How to preview a Luxor drawing

Hello all,

I am using Julia to run simulations on a given system and in my post-processing module I plot and save the results. Also, I have implemented a Luxor drawing function named drawSystem() that shows my data in a very good fashion: a .png file with the drawing of the system and with its values (e.g. temperatures, pressures, velocities, etc.). This function is invoked by the command:

@drawsvg begin drawSystem(dataframe, dimensions, settings) end

to show the drawing in Julia Plots, and it works fine when called by itself.

However, when I add the command in my post-processing module, that does not work anymore. The reason is the fact that that is not the last command of the post-processing module, and therefore it produces the drawing but it does not show it in Julia Plots. I have tried to add preview(), but it does not solve my issue.

Does anybody have a solutions? :pray:

Hi! I don’t quite understand what you mean by “display in Julia Plots”? (I’ve never used Luxor and Plots at the same time.)

Perhaps you can save a drawing as a file and then display the file, rather than rely on the ‘show last result’ mechanism.

This works quite well in a Pluto notebook.

This is what I mean: if you just execute

@drawsvg begin rect(Point(0,0), 100 ,200 ,action=:fill) end

from the Terminal, then it works and it produces the black rectangle. But if you incorporate that command in a post-processing function like in my case, it does not work simply because the last command of the function postProcess() is println().

using Luxor
function postProcess()
    println("Launching post-processing...")
    @drawsvg begin rect(Point(0,0), 100 ,200 ,action=:fill) end
    println("Post-processing finished")
end

In fact, if you change the post-processing function with:

using Luxor
function postProcess()
    println("Launching post-processing...")
    @drawsvg begin rect(Point(0,0), 100 ,200 ,action=:fill) end
end

then it works. But I can’t do it in this way because I need to have other commands afterwards.

What I would like to know is: does Luxor (or Julia in general) have a command like display() for Plots.jl which shows in Julia Plots windows my drawing even if it not the last command of postProcess()?

What happens if you call postProcess()? Does it produce the black rectangle?

using Luxor
function postProcess()
    println("Launching post-processing...")
    @drawsvg begin rect(Point(0,0), 100 ,200 ,action=:fill) end
    println("Post-processing finished")
end

Ah, you’re talking about the Plots pane in VS code? I think that shows the most recent result, so your function won’t work, since it doesn’t return the drawing. I’ll wait till I’m back in front if a computer to say much more - on the phone atm

1 Like

Same as @cormullion said: also in Pluto the drawing needs to be the return value of the cell. So if you remove the println("Post-processing finished") statement, the rectangle will be shown.

Yes exactly, removing println("Post-processing finished") would solve my issue. And this can be easily done in the example.
However this is not a solution for my real code, where the function postProcess() is part of a bigger module in which many other commands need to be executed after it. I am looking for some similar command to display() for Plots.jl… any suggestion?

It’s always worth watching Fredrik’s talk: JuliaCon 2020: display, show and print – how Julia's display system works | Fredrik Ekre .

A Luxor drawing will appear differently in different working environments. In a non-graphical environment, such as a REPL or terminal emlator, you’ll just get a text confirmation:

Luxor drawing: (type = :svg, width = 600.0, height = 600.0, 
      location = in memory) 

If you’re using VSCode, you might get some inspriration from this animation:

luxor

However, that code won’t work the same in Pluto, because Pluto is reactive, and because there’s no Plots Pane, so a drawing can be displayed if its the return value:

But in a Jupyter notebook, you’ll see something like this:

which is just a long list of SVG elements.

The author of the documentation could have done a better job of describing the return values and different behaviours of all the various options, but - perhaps the more documentation there is, the harder it is to find anything… ? :slight_smile: