Skip to content

Commit bf4c94d

Browse files
ph-kevSbozzolo
authored andcommitted
Fix models repeating in legend on box plot
This commit adds a fix to the legend of the box plot where the legend can display the same models multiple time. To prevent this, we exclude the models in `model_names` when computing the single best model and single worst model for the box plot.
1 parent d13f7c3 commit bf4c94d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ julia> reordered_var.dims |> keys |> collect
3131
"long"
3232
```
3333

34+
## Bug fixes
35+
36+
- Fix models repeating in legend of box plots by not considering the models in `model_names`
37+
when finding the best and worst models
38+
3439
v0.5.8
3540
------
3641

docs/src/visualize_rmse_var.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Instead of computing summary statistics, it may be more helpful to plot a box pl
44
heatmap. `ClimaAnalysis` provides the functions `plot_boxplot!` and `plot_leaderboard!`
55
to help visualize the root mean squared errors (RMSEs) in a `RMSEVariable`.
66

7-
The function [`Visualize.plot_boxplot!`](@ref) makes a box plot for each
8-
category in the `RMSEVariable`. The best model and worst model and any other models in
9-
`model_names` are plotted. The category to find the best and worst model defaults to
10-
"ANN", but can be changed using the parameter `best_and_worst_category_name`.
7+
The function [`Visualize.plot_boxplot!`](@ref) makes a box plot for each category in the
8+
`RMSEVariable`. The best model and worst model and any other models in `model_names` are
9+
plotted. When finding the best and worst single models, any models in `model_names` will be
10+
excluded. The category to find the best and worst model defaults to "ANN", but can be
11+
changed using the parameter `best_and_worst_category_name`.
1112

1213
The function [`Visualize.plot_leaderboard!`](@ref) makes a heatmap of the
1314
RMSEs between the variables of interest and the categories. The best model for each variable
@@ -102,4 +103,4 @@ CairoMakie.save("./assets/boxplot_and_leaderboard.png", fig)
102103
nothing # hide
103104
```
104105

105-
![box plot](./assets/boxplot_and_leaderboard.png)
106+
![box plot](./assets/boxplot_and_leaderboard.png)

ext/ClimaAnalysisMakieExt.jl

+9-4
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ end
640640
Plot a Tukey style boxplot for each category in `rmse_var`.
641641
642642
The best and worst single models are found for the category `best_and_worst_category_name`
643-
and are plotted on the boxplot. Additionally, any model in `model_names` will also be
643+
and are plotted on the boxplot. When finding the best and worst single models, any models in
644+
`model_names` will be excluded. Additionally, any model in `model_names` will also be
644645
plotted on the boxplot.
645646
646647
The parameter `ploc` determines where to place the plot on the figure.
@@ -693,15 +694,19 @@ function Visualize.plot_boxplot!(
693694
whiskerlinewidth = 1,
694695
)
695696

696-
# Plotting best and worst model
697+
# Delete any model in model_names to exclude them when finding best and worst models
698+
rmse_var_delete =
699+
ClimaAnalysis.Leaderboard._delete_model(rmse_var, model_names...)
700+
701+
# Find and plot best and worst models
697702
absolute_worst_values, absolute_worst_model_name =
698703
ClimaAnalysis.find_worst_single_model(
699-
rmse_var,
704+
rmse_var_delete,
700705
category_name = best_and_worst_category_name,
701706
)
702707
absolute_best_values, absolute_best_model_name =
703708
ClimaAnalysis.find_best_single_model(
704-
rmse_var,
709+
rmse_var_delete,
705710
category_name = best_and_worst_category_name,
706711
)
707712
Makie.scatter!(

0 commit comments

Comments
 (0)