# How to preview a Luxor drawing

**URL:** <https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298>\
**Category:** General Usage\
**Tags:** question, package, plotting, dataframes, luxor\
**Created:** [January 26, 2024, 11:48am UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298 "2024-01-26T11:48:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleppersico](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@aleppersico](https://discourse.julialang.org/u/aleppersico)\
**Post date:** [January 26, 2024, 11:48am UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/1 "2024-01-26T11:48:36Z")

</div>

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:

```julia
@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? 🙏

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 26, 2024, 11:59am UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/2 "2024-01-26T11:59:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [January 26, 2024, 12:31pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/3 "2024-01-26T12:31:24Z")

</div>

This works quite well in a Pluto notebook.

---

<div class="post-metadata">

**Author:** ![aleppersico](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@aleppersico](https://discourse.julialang.org/u/aleppersico)\
**Post date:** [January 26, 2024, 1:08pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/4 "2024-01-26T13:08:51Z")

</div>

This is what I mean: if you just execute

```julia
@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()`.

```julia
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:

```julia
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()`?

---

<div class="post-metadata">

**Author:** ![aleppersico](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@aleppersico](https://discourse.julialang.org/u/aleppersico)\
**Post date:** [January 26, 2024, 1:13pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/5 "2024-01-26T13:13:14Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 26, 2024, 1:23pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/6 "2024-01-26T13:23:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [January 26, 2024, 1:30pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/7 "2024-01-26T13:30:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aleppersico](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@aleppersico](https://discourse.julialang.org/u/aleppersico)\
**Post date:** [January 26, 2024, 1:34pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/8 "2024-01-26T13:34:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 26, 2024, 5:15pm UTC](https://discourse.julialang.org/t/how-to-preview-a-luxor-drawing/109298/9 "2024-01-26T17:15:27Z")

</div>

It’s always worth watching Fredrik’s talk: [JuliaCon 2020: display, show and print – how Julia's display system works | Fredrik Ekre](https://fredrikekre.se/posts/display-show-print/) .

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:

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce11e473e76f4a9488da88e89aa657ebab7504dc.gif)

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:

 ![Screenshot 2024-01-26 at 17.03.39](https://global.discourse-cdn.com/julialang/original/3X/0/0/00955c4f000ff89c9c5a45390bb25f6ec2b74ded.jpeg)

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

 ![Screenshot 2024-01-26 at 17.09.43](https://global.discourse-cdn.com/julialang/original/3X/b/1/b1f127d3a251276eed04f7a683530a28ad6bce45.png)

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… ? 🙂
