Skip to content

Commit

Permalink
moving legend merge again,should fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
behinger committed Nov 25, 2023
1 parent 4d367fb commit 4863f32
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GridLayoutBase = "3955a311-db13-416c-9275-1d80ed98e5e9"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down
9 changes: 9 additions & 0 deletions docs/src/tutorials/parallelcoordinates.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ plot_parallelcoordinates(subset(results_plot,:channel=>x->x.<5);
```


## Bending the parallel plot
it can be helpful to "bend" the lines

```@example main
plot_parallelcoordinates(subset(results_plot,:channel=>x->x.<5);
visual = (;color = :darkblue),ax_labels=["Fz","Cz","O1","O2"])
```
2 changes: 2 additions & 0 deletions src/UnfoldMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ using ColorTypes

using DocStringExtensions # for $SIGNATURES

using Interpolations # for parallelplot

using DataStructures
using DataFrames
using SparseArrays
Expand Down
25 changes: 22 additions & 3 deletions src/plot_parallelcoordinates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Plot a PCP (parallel coordinates plot).
- normalize (default `nothing`): can be `:minmax` to normalize each axis to their respective min-max range
- ax_labels (default `nothing`): can be a vector of labels with the length of number of `mapping.x` unique values - typically the channel name
- bend (default `false`): adds spline interpolation between the axes to "bend" the parallel plot
## Defining the axes
Expand All @@ -31,7 +32,7 @@ The input `f`
plot_parallelcoordinates(data::DataFrame; kwargs...) =
plot_parallelcoordinates(Figure(), data; kwargs...)

function plot_parallelcoordinates(f,data::DataFrame;ax_labels = nothing,normalize=nothing,kwargs...)
function plot_parallelcoordinates(f,data::DataFrame;ax_labels = nothing,normalize=nothing,bend=false,kwargs...)
config = PlotConfig(:paracoord)
UnfoldMakie.config_kwargs!(config; kwargs...)

Expand Down Expand Up @@ -71,6 +72,7 @@ function plot_parallelcoordinates(f,data::DataFrame;ax_labels = nothing,normaliz

f,ax,axlist,hlines = parallelplot(f,d5;normalize=normalize,
color=c,
bend = bend,
line_labels = line_labels,
ax_labels = ax_labels,
config.visual...)
Expand All @@ -90,6 +92,7 @@ function parallelplot(f::Union{<:Figure,<:GridPosition,<:GridLayout},
ax_labels=nothing,
normalize=:minmax,
alpha = 0.3,
bend = false,
)
@assert size(data,2) > 1 "currently more than one line has to be plotted for parallelplot to work"
if isa(color,AbstractVector)
Expand Down Expand Up @@ -119,6 +122,22 @@ function parallelplot(f::Union{<:Figure,<:GridPosition,<:GridLayout},
maxlist = maximum(plotdata)
end

# edge bending / bundling

if !bend
x_plotdata = x_pos
plotdata_int = plotdata
else
x_plotdata = range(1,x_pos[end],step=0.05)
plotdata_int = Array{Float64}(undef,length(x_plotdata),size(plotdata,2))
@debug size(plotdata)
for k = 1:size(plotdata,2)
itp = cubic_spline_interpolation(x_pos, plotdata[:,k])
plotdata_int[:,k] = itp.(x_plotdata)
end
end

# color
crange = [1,2] # default
if isnothing(color)
color = 1
Expand All @@ -137,9 +156,9 @@ function parallelplot(f::Union{<:Figure,<:GridPosition,<:GridLayout},

# plot the lines - this way it will be easy to curve them too
hlines = [];
for (ix,r) in enumerate(eachcol(plotdata))
for (ix,r) in enumerate(eachcol(plotdata_int))

h = lines!(ax,r;alpha=alpha,
h = lines!(ax,x_plotdata,r;alpha=alpha,
color = isa(color,AbstractVector) ? color[ix] : color,
colormap=colormap,
colorrange=crange,
Expand Down
4 changes: 3 additions & 1 deletion src/plotconfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function PlotConfig()# defaults
orientation = :vertical,
tellwidth = true,
tellheight = false,
merge = true,
),
(;#colorbar
vertical = true,
Expand Down Expand Up @@ -222,6 +221,9 @@ function PlotConfig(T::Val{:paracoord})
color = :black, # default linecolor
alpha = 0.3,
),
legend = (;
merge = true,
)
mapping = (; x = :channel),
)
return cfg
Expand Down

0 comments on commit 4863f32

Please sign in to comment.