# Lots of lines! in Makie

**URL:** <https://discourse.julialang.org/t/lots-of-lines-in-makie/99553>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [May 29, 2023, 11:23am UTC](https://discourse.julialang.org/t/lots-of-lines-in-makie/99553 "2023-05-29T11:23:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 29, 2023, 11:23am UTC](https://discourse.julialang.org/t/lots-of-lines-in-makie/99553/1 "2023-05-29T11:23:15Z")

</div>

I am making a plot of a dataset using semi-transparent lines connecting a bunch of measurements. MWE:

```julia
using CairoMakie, Colors
CairoMakie.activate!(type = "svg")

a = √.abs.(randn(500))
b = a .* 0.5 .+ randn() / 10
c = b .* 0.5 .+ randn() / 20

f = Figure()
ax = Axis(f[1,1]; xticks = (1:3, ["a", "b", "c"]))
ylims!(ax, (0.0, nothing))
for (a, b, c) in zip(a, b, c)
    lines!(ax, 1:3, [a, b, c]; color = colorant="0x1000")
end
f

```

which looks like

 ![x](https://global.discourse-cdn.com/julialang/original/3X/1/2/12fb5aeb98b27f9954f25cab9d9b27e9bcf8454a.png)

In the actual plot I have about 5000 calls to `lines!`. Seems to render fine in SVG too.

Is this idiomatic use of the Makie API, or can I somehow combine them into one call?

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [May 29, 2023, 11:29am UTC](https://discourse.julialang.org/t/lots-of-lines-in-makie/99553/2 "2023-05-29T11:29:57Z")

</div>

I think it’s idiomatic.

Alternatively, (I think) you can also concatenate all data into one vector, but insert a `NaN` as a separator between the data sets. The `NaN` takes care that the lines are not connected then.

But I am not sure how much this would help `CairoMakie` or `GLMakie` performance wise.  
And if you want to later make it interactive then this only seems to be hindering you in updating the values, because you would have to take the `NaN`s into account again …

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 29, 2023, 12:20pm UTC](https://discourse.julialang.org/t/lots-of-lines-in-makie/99553/3 "2023-05-29T12:20:07Z")

</div>

For GLMakie, one linecall with nans will be much more performant!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 29, 2023, 2:51pm UTC](https://discourse.julialang.org/t/lots-of-lines-in-makie/99553/4 "2023-05-29T14:51:32Z")

</div>

The `series` recipe can be used to avoid manual NaN-business, which as Simon says is the most performant. Not sure if `series` actually does this under the hood, off the top of my head.

```julia
data = reduce(hcat, [(1:50) .+ i for i in 1:50])

series(data, solid_color = (:black, 0.1))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/3/73d8424a1e2dfbefb9d414ae70d90ffc24df1e58.jpeg)

For CairoMakie, the difference in final output size should be relatively slight for SVG.
