Peculiarity with plotting `seriestype = :straightlines`

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

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

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

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


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?

HNY.

Starting with your lines data, you could simply do:

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

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…