635
635
rmse_var::ClimaAnalysis.RMSEVariable;
636
636
model_names = ["CliMA"],
637
637
ploc = (1, 1),
638
- best_and_worst_category_name = "ANN")
638
+ best_and_worst_category_name = "ANN",
639
+ legend_text_width = 10)
639
640
640
641
Plot a Tukey style boxplot for each category in `rmse_var`.
641
642
@@ -644,14 +645,16 @@ and are plotted on the boxplot. When finding the best and worst single models, a
644
645
`model_names` will be excluded. Additionally, any model in `model_names` will also be
645
646
plotted on the boxplot.
646
647
647
- The parameter `ploc` determines where to place the plot on the figure.
648
+ The parameter `ploc` determines where to place the plot on the figure. The parameter
649
+ `legend_text_width` determines the number of characters on each line in the legend.
648
650
"""
649
651
function Visualize. plot_boxplot! (
650
652
fig,
651
653
rmse_var:: ClimaAnalysis.RMSEVariable ;
652
654
model_names = [" CliMA" ],
653
655
ploc = (1 , 1 ),
654
656
best_and_worst_category_name = " ANN" ,
657
+ legend_text_width = 10 ,
655
658
)
656
659
# Unit checking
657
660
ClimaAnalysis. Leaderboard. _unit_check (rmse_var)
@@ -709,21 +712,21 @@ function Visualize.plot_boxplot!(
709
712
rmse_var_delete,
710
713
category_name = best_and_worst_category_name,
711
714
)
712
- Makie. scatter! (
715
+ best_pt = Makie. scatter! (
713
716
ax,
714
717
1 : num_cats,
715
- absolute_worst_values ,
716
- label = absolute_worst_model_name ,
718
+ absolute_best_values ,
719
+ label = absolute_best_model_name ,
717
720
)
718
- Makie. scatter! (
721
+ worst_pt = Makie. scatter! (
719
722
ax,
720
723
1 : num_cats,
721
- absolute_best_values ,
722
- label = absolute_best_model_name ,
724
+ absolute_worst_values ,
725
+ label = absolute_worst_model_name ,
723
726
)
724
727
725
728
# Plotting the median model
726
- Makie. scatter! (
729
+ median_pt = Makie. scatter! (
727
730
ax,
728
731
1 : num_cats,
729
732
ClimaAnalysis. median (rmse_var),
@@ -734,6 +737,13 @@ function Visualize.plot_boxplot!(
734
737
visible = false ,
735
738
)
736
739
740
+ # Keep track of points plotted by scatter! and names for plotting the legend
741
+ # later
742
+ pts_on_boxplot = [median_pt, best_pt, worst_pt]
743
+ names_on_legend = vcat (
744
+ [" Median" , absolute_best_model_name, absolute_worst_model_name],
745
+ model_names,
746
+ )
737
747
# Plot CliMA model and other models
738
748
for model_name in model_names
739
749
ClimaAnalysis. Leaderboard. _model_name_check (rmse_var, model_name)
@@ -746,7 +756,7 @@ function Visualize.plot_boxplot!(
746
756
marker = :star5 ,
747
757
markersize = 20 ,
748
758
color = :green ,
749
- )
759
+ ) |> pt -> push! (pts_on_boxplot, pt)
750
760
else
751
761
Makie. scatter! (
752
762
ax,
@@ -755,12 +765,22 @@ function Visualize.plot_boxplot!(
755
765
label = model_name,
756
766
markersize = 20 ,
757
767
color = :red ,
758
- )
768
+ ) |> pt -> push! (pts_on_boxplot, pt)
759
769
end
760
770
end
761
771
772
+ # Add a new line character every `legend_text_width` characters to prevent legend from
773
+ # overflowing onto the box plot
774
+ # Soln from
775
+ # https://stackoverflow.com/questions/40545980/insert-a-newline-character-every-10-characters-in-a-string-using-julia
776
+ names_on_legend = map (
777
+ name ->
778
+ replace (name, Regex (" (.{$legend_text_width })" ) => s "\1\n " ) |>
779
+ (name -> rstrip (name, ' \n ' )),
780
+ names_on_legend,
781
+ )
762
782
# Hack to make legend appear better
763
- Makie. axislegend ()
783
+ Makie. axislegend (ax, pts_on_boxplot, names_on_legend )
764
784
Makie. scatter! (ax, [num_cats + 2.5 ], [0.1 ], markersize = 0.01 )
765
785
end
766
786
0 commit comments