Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump Makie compat to 0.20 #108

Merged
merged 6 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request:
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - Makie - ${{ matrix.makie }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -22,6 +22,8 @@ jobs:
- ubuntu-latest
arch:
- x64
makie:
- '0.20'
Comment on lines +25 to +26
Copy link
Member

@kimlaberinto kimlaberinto Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

env:
JULIA_NUM_THREADS: 2
steps:
Expand All @@ -37,11 +39,16 @@ jobs:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-artifacts-${{ hashFiles('**/Project.toml') }}
restore-keys: ${{ runner.os }}-test-artifacts
- uses: julia-actions/julia-buildpkg@v1
- name: "Install Makie and instantiate project"
shell: julia --color=yes --project {0}
run: |
using Pkg
Pkg.add(Pkg.PackageSpec(; name="Makie", version="${{ matrix.makie }}"))
Pkg.instantiate()
palday marked this conversation as resolved.
Show resolved Hide resolved
- uses: julia-actions/julia-runtest@v1
- name: Percy Upload
uses: percy/[email protected]
if: matrix.version == 1
if: ${{ matrix.version == 1 && matrix.makie == 0.20 }}
with:
custom-command: "npx @percy/cli upload ./test/plot_results"
env:
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lighthouse"
uuid = "ac2c24cd-07f0-4848-96b2-1b82c3ea0e59"
authors = ["Beacon Biosignals, Inc."]
version = "0.15.2"
version = "0.16.0"

[deps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Expand All @@ -21,11 +21,11 @@ TensorBoardLogger = "899adc3e-224a-11e9-021f-63837185c80f"
[compat]
Arrow = "2.3"
ArrowTypes = "1, 2"
CairoMakie = "0.7, 0.8"
CairoMakie = "0.11"
DataFrames = "1.3"
Legolas = "0.5"
Makie = "0.17.4, 0.18"
StatsBase = "0.33"
Makie = "0.20"
StatsBase = "0.33, 0.34"
Tables = "1.7"
TensorBoardLogger = "0.1"
julia = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fig, ax, p = plot_confusion_matrix(confusion, classes)
```

```@example 1
fig = Figure(resolution=(800, 400))
fig = Figure(size=(800, 400))
plot_confusion_matrix!(fig[1, 1], confusion, classes, :Row, annotation_text_size=14)
plot_confusion_matrix!(fig[1, 2], confusion, classes, :Column, annotation_text_size=14)
fig
Expand Down
66 changes: 30 additions & 36 deletions src/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
if !isdefined(Makie, :FigurePosition)
const FigurePosition = Makie.GridPosition
get_parent(x::Makie.GridPosition) = x.layout.parent
else
using Makie: FigurePosition
get_parent(x::FigurePosition) = x.fig
end
get_parent(x::Makie.GridPosition) = x.layout.parent

# We can't rely on inference to always give us fully typed
# Vector{<: Number} so we add `{T} where T` to the the mix
Expand All @@ -23,7 +17,7 @@ function get_theme(scene, key1::Symbol, key2::Symbol; defaults...)
return get_theme(Makie.get_scene(scene), key1, key2; defaults...)
end

function get_theme(fig::FigurePosition, key1::Symbol, key2::Symbol; defaults...)
function get_theme(fig::GridPosition, key1::Symbol, key2::Symbol; defaults...)
return get_theme(get_parent(fig), key1, key2; defaults...)
end

Expand Down Expand Up @@ -64,7 +58,7 @@ A series of XYVectors, or a single xyvector.
"""
const SeriesCurves = Union{XYVector,AbstractVector{<:XYVector}}

function series_plot!(subfig::FigurePosition, per_class_pr_curves::SeriesCurves,
function series_plot!(subfig::GridPosition, per_class_pr_curves::SeriesCurves,
class_labels::Union{Nothing,AbstractVector{String}}; legend=:lt,
title="No title",
xlabel="x label", ylabel="y label", solid_color=nothing,
Expand Down Expand Up @@ -92,7 +86,7 @@ function series_plot!(subfig::FigurePosition, per_class_pr_curves::SeriesCurves,
return ax
end

function plot_pr_curves!(subfig::FigurePosition, per_class_pr_curves::SeriesCurves,
function plot_pr_curves!(subfig::GridPosition, per_class_pr_curves::SeriesCurves,
class_labels::Union{Nothing,AbstractVector{String}}; legend=:lt,
title="PR curves",
xlabel="True positive rate", ylabel="Precision",
Expand All @@ -103,7 +97,7 @@ function plot_pr_curves!(subfig::FigurePosition, per_class_pr_curves::SeriesCurv
ylabel=ylabel, scatter=scatter, solid_color=solid_color)
end

function plot_roc_curves!(subfig::FigurePosition, per_class_roc_curves::SeriesCurves,
function plot_roc_curves!(subfig::GridPosition, per_class_roc_curves::SeriesCurves,
per_class_roc_aucs::NumberVector,
class_labels::AbstractVector{<:String};
legend=:rb, title="ROC curves", xlabel="False positive rate",
Expand All @@ -116,7 +110,7 @@ function plot_roc_curves!(subfig::FigurePosition, per_class_roc_curves::SeriesCu
ylabel=ylabel)
end

function plot_reliability_calibration_curves!(subfig::FigurePosition,
function plot_reliability_calibration_curves!(subfig::GridPosition,
per_class_reliability_calibration_curves::SeriesCurves,
per_class_reliability_calibration_scores::NumberVector,
class_labels::AbstractVector{String};
Expand Down Expand Up @@ -152,7 +146,7 @@ function set_from_kw!(theme, key, kw, default)
return
end

function plot_binary_discrimination_calibration_curves!(subfig::FigurePosition,
function plot_binary_discrimination_calibration_curves!(subfig::GridPosition,
calibration_curve::SeriesCurves,
calibration_score,
per_expert_calibration_curves::Union{SeriesCurves,
Expand Down Expand Up @@ -204,7 +198,7 @@ function plot_binary_discrimination_calibration_curves!(subfig::FigurePosition,
return ax
end

function plot_confusion_matrix!(subfig::FigurePosition, confusion::NumberMatrix,
function plot_confusion_matrix!(subfig::GridPosition, confusion::NumberMatrix,
class_labels::AbstractVector{String},
normalize_by::Union{Symbol,Nothing}=nothing;
annotation_text_size=20, colormap=:Blues)
Expand All @@ -221,7 +215,7 @@ function plot_confusion_matrix!(subfig::FigurePosition, confusion::NumberMatrix,
title = "$(string(normalize_by))-Normalized Confusion"
end
class_indices = 1:nclasses
text_theme = get_theme(subfig, :ConfusionMatrix, :Text; textsize=annotation_text_size)
text_theme = get_theme(subfig, :ConfusionMatrix, :Text; fontsize=annotation_text_size)
heatmap_theme = get_theme(subfig, :ConfusionMatrix, :Heatmap; nan_color=(:black, 0.0))
axis_theme = get_theme(subfig, :ConfusionMatrix, :Axis; xticklabelrotation=pi / 4,
titlealign=:left, title,
Expand Down Expand Up @@ -255,7 +249,7 @@ function plot_confusion_matrix!(subfig::FigurePosition, confusion::NumberMatrix,
annos = vec([(string(confusion[i, j]), Point2f(j, i))
for i in class_indices, j in class_indices])
colors = vec([label_color(i, j) for i in class_indices, j in class_indices])
text!(ax, annos; align=(:center, :center), color=colors, textsize=annotation_text_size,
text!(ax, annos; align=(:center, :center), color=colors, fontsize=annotation_text_size,
text_theme...)
return ax
end
Expand All @@ -282,15 +276,15 @@ function text_attributes(values, groups, bar_colors, bg_color, text_color)
return aligns, offsets, text_colors
end

function plot_kappas!(subfig::FigurePosition, per_class_kappas::NumberVector,
function plot_kappas!(subfig::GridPosition, per_class_kappas::NumberVector,
class_labels::AbstractVector{String}, per_class_IRA_kappas=nothing;
color=[:lightgrey, :lightblue], annotation_text_size=20)
nclasses = length(class_labels)
axis_theme = get_theme(subfig, :Kappas, :Axis; aspect=AxisAspect(1), titlealign=:left,
xlabel="Cohen's kappa", xticks=[0, 1], yreversed=true,
yticks=(1:nclasses, class_labels))

text_theme = get_theme(subfig, :Kappas, :Text; textsize=annotation_text_size)
text_theme = get_theme(subfig, :Kappas, :Text; fontsize=annotation_text_size)
text_color = to_color(to_value(pop!(text_theme, :color, to_color(:black))))
bars_theme = get_theme(subfig, :Kappas, :BarPlot; color=color)
bar_colors = to_color.(bars_theme.color[])
Expand Down Expand Up @@ -340,7 +334,7 @@ function plot_kappas!(subfig::FigurePosition, per_class_kappas::NumberVector,
end

"""
evaluation_metrics_plot(data::Dict; resolution=(1000, 1000), textsize=12)
evaluation_metrics_plot(data::Dict; size=(1000, 1000), fontsize=12)
evaluation_metrics_plot(row::EvaluationV1; kwargs...)

Plot all evaluation metrics generated via [`evaluation_metrics_record`](@ref) and/or
Expand All @@ -350,16 +344,16 @@ function evaluation_metrics_plot(data::Dict; kwargs...)
return evaluation_metrics_plot(EvaluationV1(data); kwargs...)
end

function evaluation_metrics_plot(row::EvaluationV1; resolution=(1000, 1000),
textsize=12)
fig = Figure(; resolution=resolution, Axis=(titlesize=17,))
function evaluation_metrics_plot(row::EvaluationV1; size=(1000, 1000),
fontsize=12)
fig = Figure(; size=size, Axis=(titlesize=17,))

# Confusion
plot_confusion_matrix!(fig[1, 1], row.confusion_matrix, row.class_labels,
:Column;
annotation_text_size=textsize)
annotation_text_size=fontsize)
plot_confusion_matrix!(fig[1, 2], row.confusion_matrix, row.class_labels, :Row;
annotation_text_size=textsize)
annotation_text_size=fontsize)
# Kappas
IRA_kappa_data = nothing
multiclass = length(row.class_labels) > 2
Expand All @@ -375,7 +369,7 @@ function evaluation_metrics_plot(row::EvaluationV1; resolution=(1000, 1000),
end

plot_kappas!(fig[1, 3], kappa_data, labels, IRA_kappa_data;
annotation_text_size=textsize)
annotation_text_size=fontsize)

# Curves
ax = plot_roc_curves!(fig[2, 1], row.per_class_roc_curves,
Expand Down Expand Up @@ -428,21 +422,21 @@ function evaluation_metrics_plot(row::EvaluationV1; resolution=(1000, 1000),
end

# Helper to more easily define the non mutating versions
function axisplot(func, args; resolution=(800, 600), plot_kw...)
fig = Figure(; resolution=resolution)
function axisplot(func, args; size=(800, 600), plot_kw...)
fig = Figure(; size=size)
ax = func(fig[1, 1], args...; plot_kw...)
# ax.plots[1] is not really that great, but there isn't a FigureAxis object right now
# this will need to wait for when we figure out a better recipe integration
return Makie.FigureAxisPlot(fig, ax, ax.scene.plots[1])
end

"""
plot_confusion_matrix!(subfig::FigurePosition, args...; kw...)
plot_confusion_matrix!(subfig::GridPosition, args...; kw...)

plot_confusion_matrix(confusion::AbstractMatrix{<: Number},
class_labels::AbstractVector{String},
normalize_by::Union{Symbol,Nothing}=nothing;
resolution=(800,600), annotation_text_size=20)
size=(800,600), annotation_text_size=20)


Lighthouse plots confusion matrices, which are simple tables
Expand All @@ -467,7 +461,7 @@ plot_confusion_matrix(args...; kw...) = axisplot(plot_confusion_matrix!, args; k
plot_reliability_calibration_curves(per_class_reliability_calibration_curves::SeriesCurves,
per_class_reliability_calibration_scores::NumberVector,
class_labels::AbstractVector{String};
legend=:rb, resolution=(800, 600))
legend=:rb, size=(800, 600))

"""
function plot_reliability_calibration_curves(args...; kw...)
Expand All @@ -489,11 +483,11 @@ function plot_binary_discrimination_calibration_curves(args...; kw...)
end

"""
plot_pr_curves!(subfig::FigurePosition, args...; kw...)
plot_pr_curves!(subfig::GridPosition, args...; kw...)

plot_pr_curves(per_class_pr_curves::SeriesCurves,
class_labels::AbstractVector{<: String};
resolution=(800, 600),
size=(800, 600),
legend=:lt, title="PR curves",
xlabel="True positive rate", ylabel="Precision",
linewidth=2, scatter=NamedTuple(), color=:darktest)
Expand All @@ -504,12 +498,12 @@ end
plot_pr_curves(args...; kw...) = axisplot(plot_pr_curves!, args; kw...)

"""
plot_roc_curves!(subfig::FigurePosition, args...; kw...)
plot_roc_curves!(subfig::GridPosition, args...; kw...)

plot_roc_curves(per_class_roc_curves::SeriesCurves,
per_class_roc_aucs::NumberVector,
class_labels::AbstractVector{<: String};
resolution=(800, 600),
size=(800, 600),
legend=:lt,
title="ROC curves",
xlabel="False positive rate",
Expand All @@ -522,12 +516,12 @@ plot_pr_curves(args...; kw...) = axisplot(plot_pr_curves!, args; kw...)
plot_roc_curves(args...; kw...) = axisplot(plot_roc_curves!, args; kw...)

"""
plot_kappas!(subfig::FigurePosition, args...; kw...)
plot_kappas!(subfig::GridPosition, args...; kw...)

plot_kappas(per_class_kappas::NumberVector,
class_labels::AbstractVector{String},
per_class_IRA_kappas=nothing;
resolution=(800, 600),
size=(800, 600),
annotation_text_size=20)
"""
plot_kappas(args...; kw...) = axisplot(plot_kappas!, args; kw...)
Expand Down
Loading