KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Support Coordinate from StaticArray #168

Closed yakir12 closed 5 years ago

yakir12 commented 5 years ago

I think it's not uncommon to hold coordinates in a StaticArrays.SVector. It would be nice to plot such trajectories without doing something like this:

using PGFPlotsX, StaticArray
xy = rand(SVector{2,Float64}, 10)
@pgf Plot(Coordinates(first.(xy), last.(xy)))

but instead:

@pgf Plot(Coordinates(xy))
tpapp commented 5 years ago
Plot(Coordinates(xy...))

should just work.

(Incidentally, you don't need the @pgf macro unless you are using options specified with {}s.)

yakir12 commented 5 years ago

but isn't splatting "slow"?

tpapp commented 5 years ago

Not for SVectors.

Also, for this particular library, you should not care since the LaTeX runtime will dominate everything.

yakir12 commented 5 years ago

awesome, thanks.

yakir12 commented 5 years ago

Plot(Coordinates(xy...)) should just work.

Actually:

julia> @pgf Plot(Coordinates(xy...))
ERROR: MethodError: no method matching Coordinates(::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},Float64,1,2})
tpapp commented 5 years ago

Sorry, missed the fact that you want to use Coordinates, not Coordinate. The following works:

using PGFPlotsX, StaticArrays
xy = rand(SVector{2,Float64}, 10)
@pgf Plot(Coordinates(Tuple.(xy)))