# Packages for Drawing and Graphics

**URL:** <https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153>\
**Category:** Visualization\
**Created:** [January 29, 2021, 12:49am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153 "2021-01-29T00:49:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 12:49am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/1 "2021-01-29T00:49:07Z")

</div>

What packages do I use for graphics? I found Cairo.jl and Graphics.jl the latter says it uses the former as a backend, but Graphics.jl is missing a lot of docstrings and looks abandoned.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [January 29, 2021, 1:31am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/2 "2021-01-29T01:31:48Z")

</div>

[Compose.jl](https://github.com/GiovineItalia/Compose.jl)

```julia
using Colors, Compose
set_default_graphic_size(14cm,10cm)

petal=[[(0.4, 0.4), (0.4, 0.2), (0.5, 0.0)],[(0.6, 0.2), (0.6, 0.4), (0.5, 0.5)]]
petalf(θ::Float64) = (context(rotation=Rotation(θ, 0.5,0.5)),
    bezigon((0.5, 0.5), petal), fill(LCHuvA(70.,50., 360*θ/2π, 0.4)))

theta = range(π/20, 2π, step=2π/10).-π
img = compose(context(), petalf.(theta)...)

```

![bezigon](https://global.discourse-cdn.com/julialang/original/3X/7/5/750bee27bc93106d5eb1bec44d61cf38abf2bfdc.png)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 29, 2021, 1:33am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/3 "2021-01-29T01:33:57Z")

</div>

[https://github.com/JuliaGraphics/Luxor.jl](https://github.com/JuliaGraphics/Luxor.jl)

It’s fairly well documented.

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [January 29, 2021, 2:28am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/4 "2021-01-29T02:28:35Z")

</div>

Huge thanks to @cormullion for creating Luxor.jl!

Also, if you are curious about making animations of different kinds, check out Javis.jl

> **[GitHub - JuliaAnimators/Javis.jl: Julia Animations and Visualizations](https://github.com/JuliaAnimators/Javis.jl)**
>
> Julia Animations and Visualizations. Contribute to JuliaAnimators/Javis.jl development by creating an account on GitHub.

Here is an example of a fun animation @ric.cioffi contributed to Javis with!

![](https://global.discourse-cdn.com/julialang/original/3X/3/2/32d04d155dc9357b4fba1a80674f00bb4a7e95a1.gif)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 2:50am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/5 "2021-01-29T02:50:11Z")

</div>

I can’t find a tutorial or command list in the documentation.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 2:51am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/6 "2021-01-29T02:51:27Z")

</div>

The first example in the tutorial through an error, because it doesn’t recognise rectangle(), not a good sign.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [January 29, 2021, 3:03am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/7 "2021-01-29T03:03:20Z")

</div>

Please provide a mwe, this works for me:

```julia
composition = compose(compose(context(), rectangle()), fill("tomato"))

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 3:21am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/8 "2021-01-29T03:21:18Z")

</div>

```julia
	composition = compose(context(),
        (context(), circle(), fill("bisque")),
        (context(), rectangle(), fill("tomato")))
	composition |> SVG("tomato_bisque.svg")

```

circle not defined

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [January 29, 2021, 3:24am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/9 "2021-01-29T03:24:42Z")

</div>

That example also works for me, please show the error trace.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 3:26am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/10 "2021-01-29T03:26:33Z")

</div>

```julia

UndefVarError: circle not defined

top-level scope@Local: 2

```

[/quote]

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 3:31am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/11 "2021-01-29T03:31:40Z")

</div>

I think the circle no recognized, was because I had Luxor loaded. now I get

```julia
MethodError: no method matching Compose.SVG(::IOStream, ::Measures.Length{:cx, Int64}, ::Measures.Length{:cy, Int64}, ::Bool, ::Symbol; ownedfile=true, filename="tomato_bisque.svg")

Closest candidates are:

Compose.SVG(::Any, ::Any, ::Any, ::Any, ::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any) at /home/brett/.julia/packages/Compose/AeWZ8/src/svg.jl:126 got unsupported keyword arguments "ownedfile", "filename"

Compose.SVG(::IO, !Matched::Measures.AbsoluteLength, !Matched::Measures.AbsoluteLength, ::Bool, ::Symbol; cached_out, id, indentation, property_stack, vector_properties, clippaths, batches, embobj, finished, ownedfile, filename, current_id, has_current_id, id_count, jsheader, jsmodules, scripts, withjs, panelcoords) at /home/brett/.julia/packages/Compose/AeWZ8/src/svg.jl:203

Compose.SVG(::IO, !Matched::Measures.AbsoluteLength, !Matched::Measures.AbsoluteLength, ::Bool) at /home/brett/.julia/packages/Compose/AeWZ8/src/svg.jl:203 got unsupported keyword arguments "ownedfile", "filename"

...

Compose.SVG(::String, ::Measures.Length{:cx, Int64}, ::Measures.Length{:cy, Int64}, ::Symbol)@svg.jl:274
top-level scope@Local: 5[inlined]

```

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [January 29, 2021, 3:41am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/12 "2021-01-29T03:41:41Z")

</div>

Without an example I can’t tell how you got that error, but using [Absolute units](https://giovineitalia.github.io/Compose.jl/latest/tutorial/#Measures-can-be-a-combination-of-absolute-and-relative-units) works for me:

```julia
 composition |> SVG("tomato_bisque.svg", 10cm, 5cm)

```

---

<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 29, 2021, 9:32am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/13 "2021-01-29T09:32:19Z")

</div>

Compose.jl and Luxor.jl have different philosophies. Compose.jl is a sophisticated high-level environment for making layouts using declarative graphics, and one of its jobs is to provide a backend for the much-loved Gadfly.jl plotting package. Luxor.jl is designed to be an easy to use procedural wrapper or “scripting language” for the powerful Cairo.jl graphics engine.

So @Mattriks’ elegant Compose.jl example above could be translated into a sequence of simple Luxor.jl instructions:

```julia
using Luxor, Colors

Drawing("A4", :svg)
origin()
for θ in range(π/20, 2π, step=2π/10) .- π
    setcolor(LCHuvA(70.,50., 360θ/2π, 0.4))
    petal = makebezierpath([O, Point(100, -50), Point(250, 0), 
           Point(250, 0), Point(100, 50)], smoothing=0.8)
    @layer begin
        rotate(θ)
        drawbezierpath(petal, :fill)
    end
end
finish()
preview()

```

 ![Screenshot 2021-01-29 at 09.18.09](https://global.discourse-cdn.com/julialang/original/3X/f/6/f68e85ddd253afffd44079c30a8bf21d81269de9.png)

so slightly longer, slightly less “composed”.

Compose.jl will be better for layout-oriented work, particularly if “trees can be defined most tersely using S-expressions” ([↗](https://giovineitalia.github.io/Compose.jl/latest/tutorial/#The-compose-function-accepts-S-expressions)) floats your boat. But if you’d prefer to just bash out some simple instructions to get some basic graphics done, Luxor.jl can probably oblige.

---

<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 29, 2021, 10:33am UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/14 "2021-01-29T10:33:43Z")

</div>

> [@brett\_knoss](#):
>
> I can’t find a tutorial or command list in the documentation.

Can you see this anywhere?

 ![Screenshot 2021-01-29 at 10.32.29](https://global.discourse-cdn.com/julialang/original/3X/d/3/d3a07edb51f47e1a833d52c3218244fe785a1966.png)

You need to click one of these first:

![Screenshot 2021-01-29 at 10.34.30](https://global.discourse-cdn.com/julialang/original/3X/e/6/e68d0bc21d81b2778f92281e75bc2366ec954a87.png)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [January 29, 2021, 4:14pm UTC](https://discourse.julialang.org/t/packages-for-drawing-and-graphics/54153/15 "2021-01-29T16:14:12Z")

</div>

Thanks, I found it.
