# Peculiarity with plotting \`seriestype = :straightlines\`

**URL:** <https://discourse.julialang.org/t/peculiarity-with-plotting-seriestype-straightlines/92299>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [December 30, 2022, 1:22am UTC](https://discourse.julialang.org/t/peculiarity-with-plotting-seriestype-straightlines/92299 "2022-12-30T01:22:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [December 30, 2022, 1:22am UTC](https://discourse.julialang.org/t/peculiarity-with-plotting-seriestype-straightlines/92299/1 "2022-12-30T01:22:31Z")

</div>

I’m trying to plot a bunch of infinite straight lines, where each line is defined by a pair of points.

```julia
julia> lines = hcat([[(0, 0), (cos(θ), sin(θ))] for θ=range(0, π, 10)]...)
2×10 Matrix{Tuple{Real, Real}}:
 (0, 0) (0, 0) (0, 0) … (0, 0)
 (1.0, 0.0) (0.939693, 0.34202) (0.766044, 0.642788) (-1.0, 1.22465e-16)

```

(Each column of `lines` defines a line.)  
This can be done with

```julia
using Plots
plot(vec(lines), seriestype = :straightline)

```

except that I get this complaint:  
`
AssertionError: Misformed data. straightline_data either accepts vectors of length 2 or 3k. The provided series has length 20
`  
I’m not sure why it accepts a pair of points or a multiple of three points.  
I can get around this by adding placeholder points:

```julia
julia> lines_with_dummy_points = [lines; fill((NaN, NaN), 1, size(lines, 2))]
3×10 Matrix{Tuple{Real, Real}}:
 (0, 0) (0, 0) (0, 0) … (0, 0)
 (1.0, 0.0) (0.939693, 0.34202) (0.766044, 0.642788) (-1.0, 1.22465e-16)
 (NaN, NaN) (NaN, NaN) (NaN, NaN) (NaN, NaN)

```

and then this plots as expected:

```julia
plot(vec(lines_with_dummy_points), seriestype = :straightline)

```

 ![Plot output](https://global.discourse-cdn.com/julialang/original/3X/1/d/1d81a64ee82697b7acc04a49f4172bac168cbbf5.png)

* * *

My question is: **why**?

It’s ugly having to inject my data with dummy points in every third position. These points don’t appear to influence the plot (except for affecting the axis limits), so why does `:straightlines` expect data in the shape 3n?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 2, 2023, 10:58pm UTC](https://discourse.julialang.org/t/peculiarity-with-plotting-seriestype-straightlines/92299/2 "2023-01-02T22:58:43Z")

</div>

HNY.

Starting with your `lines` data, you could simply do:

```julia
X, Y = first.(lines), last.(lines)
plot(X, Y, c=:blue, st=:straightline) # straigthline not needed

```

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [January 4, 2023, 1:06am UTC](https://discourse.julialang.org/t/peculiarity-with-plotting-seriestype-straightlines/92299/3 "2023-01-04T01:06:27Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> X, Y = first.(lines), last.(lines)
> plot(X, Y, c=:blue, st=:straightline) # straigthline not needed
> 
> ```

Thanks!  
Just to clarify, the pattern is `plot(X, Y)` where `X` and `Y` are 2×n matrices containing the x/y coordinates of n point pairs (each column being a pair defining a line). And `seriestype=:straightline` displays the lines with infinite extent.

This makes each line a separate series with its own colour/legend entry, which may or may not be desired. For them to be part of the same series, `X` and `Y` have to be vectors with length 3n, where each third is skipped as explained above…
