Skip to content

Commit

Permalink
bump Makie compat to 0.20 (#108)
Browse files Browse the repository at this point in the history
* bump Makie compat

* bump StatsBase compat
  • Loading branch information
palday authored Dec 15, 2023
1 parent b1adbe8 commit 2008c9f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
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'
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()
- 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

2 comments on commit 2008c9f

@palday
Copy link
Member Author

@palday palday commented on 2008c9f Dec 15, 2023

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/97175

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.0 -m "<description of version>" 2008c9fc843ce03492eaa7e17f4379a4e032d8e1
git push origin v0.16.0

Please sign in to comment.