Skip to content

Commit b38946e

Browse files
committed
Improve plotting legends
1 parent 7b5a071 commit b38946e

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

ext/VortexStepMethodMakieExt.jl

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -555,43 +555,37 @@ function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, la
555555
lines!(ax_cl, Vector(y_coords), Vector(results["cl_distribution"]),
556556
label="$label CL: $value")
557557
end
558-
axislegend(ax_cl, position=:lt)
559558

560559
# Plot CD
561560
for (y_coords, results, label) in zip(y_coordinates_list, results_list, label_list)
562561
value = round(results["cd"], digits=2)
563562
lines!(ax_cd, Vector(y_coords), Vector(results["cd_distribution"]),
564563
label="$label CD: $value")
565564
end
566-
axislegend(ax_cd, position=:lt)
567565

568566
# Plot Gamma
569567
for (y_coords, results, label) in zip(y_coordinates_list, results_list, label_list)
570568
lines!(ax_gamma, Vector(y_coords), Vector(results["gamma_distribution"]),
571569
label=label)
572570
end
573-
axislegend(ax_gamma, position=:lt)
574571

575572
# Plot alpha geometric
576573
for (y_coords, results, label) in zip(y_coordinates_list, results_list, label_list)
577574
lines!(ax_alpha_geo, Vector(y_coords), Vector(results["alpha_geometric"]),
578575
label=label)
579576
end
580-
axislegend(ax_alpha_geo, position=:lt)
581577

582578
# Plot alpha at ac
583579
for (y_coords, results, label) in zip(y_coordinates_list, results_list, label_list)
584580
lines!(ax_alpha_ac, Vector(y_coords), Vector(results["alpha_at_ac"]),
585581
label=label)
586582
end
587-
axislegend(ax_alpha_ac, position=:lt)
588583

589584
# Plot alpha uncorrected
590585
for (y_coords, results, label) in zip(y_coordinates_list, results_list, label_list)
591586
lines!(ax_alpha_unc, Vector(y_coords), Vector(results["alpha_uncorrected"]),
592587
label=label)
593588
end
594-
axislegend(ax_alpha_unc, position=:lt)
595589

596590
# Plot force components
597591
force_axes = [ax_fx, ax_fy, ax_fz]
@@ -607,9 +601,12 @@ function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, la
607601
lines!(ax, Vector(y_coords), Vector(forces),
608602
label="$label ΣF$comp: $total_force N")
609603
end
610-
axislegend(ax, position=:lt)
611604
end
612605

606+
# Shared legend at bottom of grid
607+
Legend(fig[4, :], ax_gamma;
608+
orientation=:horizontal, tellwidth=false, tellheight=true)
609+
613610
# Save and show
614611
if is_save
615612
save_plot(fig, save_path, title, data_type=data_type)
@@ -799,7 +796,8 @@ function VortexStepMethod.plot_polars(
799796
save_path=nothing,
800797
is_save=true,
801798
is_show=true,
802-
use_tex=false
799+
use_tex=false,
800+
cl_over_cd=true,
803801
)
804802
# Validate inputs
805803
total_cases = length(body_aero_list) + length(literature_path_list)
@@ -848,8 +846,13 @@ function VortexStepMethod.plot_polars(
848846
xlabel="$angle_type [°]", ylabel="CD")
849847
ax_cs = Axis(fig[2, 1], title="CS vs $angle_type [°]",
850848
xlabel="$angle_type [°]", ylabel="CS")
851-
ax_polar = Axis(fig[2, 2], title="CL vs CD",
852-
xlabel="CD", ylabel="CL")
849+
ax_fourth = if cl_over_cd
850+
Axis(fig[2, 2], title="CL/CD vs $angle_type [°]",
851+
xlabel="$angle_type [°]", ylabel="CL/CD")
852+
else
853+
Axis(fig[2, 2], title="CL vs CD",
854+
xlabel="CD", ylabel="CL")
855+
end
853856

854857
# Number of computational results
855858
n_solvers = length(solver_list)
@@ -864,7 +867,6 @@ function VortexStepMethod.plot_polars(
864867
ylims!(ax_cl, -0.5, 2)
865868
end
866869
end
867-
axislegend(ax_cl, position=:lt)
868870

869871
# Plot CD vs angle
870872
for (i, (polar_data, label)) in enumerate(zip(polar_data_list, labels_with_re))
@@ -876,7 +878,6 @@ function VortexStepMethod.plot_polars(
876878
ylims!(ax_cd, -0.5, 2)
877879
end
878880
end
879-
axislegend(ax_cd, position=:lt)
880881

881882
# Plot CS vs angle
882883
for (i, (polar_data, label)) in enumerate(zip(polar_data_list, labels_with_re))
@@ -888,20 +889,28 @@ function VortexStepMethod.plot_polars(
888889
ylims!(ax_cs, -0.5, 2)
889890
end
890891
end
891-
axislegend(ax_cs, position=:lt)
892892

893-
# Plot CL vs CD
893+
# Plot fourth panel: CL/CD vs angle or CL vs CD
894894
for (i, (polar_data, label)) in enumerate(zip(polar_data_list, labels_with_re))
895895
marker = i <= n_solvers ? :star5 : :circle
896896
markersize = i <= n_solvers ? 12 : 8
897-
scatterlines!(ax_polar, polar_data[3], polar_data[2];
898-
label=label, marker=marker, markersize=markersize)
899-
if maximum(polar_data[2]) > 10 || maximum(polar_data[3]) > 10
900-
ylims!(ax_polar, -0.5, 2)
901-
xlims!(ax_polar, -0.5, 2)
897+
if cl_over_cd
898+
cl_cd = polar_data[2] ./ polar_data[3]
899+
scatterlines!(ax_fourth, polar_data[1], cl_cd;
900+
label=label, marker=marker, markersize=markersize)
901+
else
902+
scatterlines!(ax_fourth, polar_data[3], polar_data[2];
903+
label=label, marker=marker, markersize=markersize)
904+
if maximum(polar_data[2]) > 10 || maximum(polar_data[3]) > 10
905+
ylims!(ax_fourth, -0.5, 2)
906+
xlims!(ax_fourth, -0.5, 2)
907+
end
902908
end
903909
end
904-
axislegend(ax_polar, position=:lt)
910+
911+
# Shared legend at bottom of grid
912+
Legend(fig[3, :], ax_cl;
913+
orientation=:horizontal, tellwidth=false, tellheight=true)
905914

906915
# Save and show
907916
if is_save && !isnothing(save_path)
@@ -1038,6 +1047,7 @@ function VortexStepMethod.plot_combined_analysis(
10381047
save_path=nothing,
10391048
is_save=false,
10401049
angle_of_attack_for_spanwise_distribution=5.0,
1050+
cl_over_cd=true,
10411051
)
10421052
# Normalize inputs to arrays for consistent handling
10431053
solvers = solver isa Vector ? solver : [solver]
@@ -1258,10 +1268,8 @@ function VortexStepMethod.plot_combined_analysis(
12581268
end
12591269
end
12601270

1261-
for ax in [ax_cl, ax_cd, ax_gamma, ax_alpha_geo, ax_alpha_ac,
1262-
ax_alpha_unc, ax_fx, ax_fy, ax_fz]
1263-
axislegend(ax, position=:lt)
1264-
end
1271+
Legend(fig[2, 1][4, :], ax_gamma;
1272+
orientation=:horizontal, tellwidth=false, tellheight=true)
12651273

12661274
# force y-limits
12671275
ylims!(ax_alpha_geo, -0.25 * aoa_span, 1.1 * aoa_span)
@@ -1323,8 +1331,13 @@ function VortexStepMethod.plot_combined_analysis(
13231331
xlabel="$angle_type [°]", ylabel="CD")
13241332
ax_cs_polar = Axis(fig[2, 2][2, 1], title="CS vs $angle_type [°]",
13251333
xlabel="$angle_type [°]", ylabel="CS")
1326-
ax_polar = Axis(fig[2, 2][2, 2], title="CL vs CD",
1327-
xlabel="CD", ylabel="CL")
1334+
ax_fourth_polar = if cl_over_cd
1335+
Axis(fig[2, 2][2, 2], title="CL/CD vs $angle_type [°]",
1336+
xlabel="$angle_type [°]", ylabel="CL/CD")
1337+
else
1338+
Axis(fig[2, 2][2, 2], title="CL vs CD",
1339+
xlabel="CD", ylabel="CL")
1340+
end
13281341

13291342
for (idx, (pd, lbl)) in enumerate(polar_series)
13301343
color = colors[mod1(idx, length(colors))]
@@ -1334,12 +1347,18 @@ function VortexStepMethod.plot_combined_analysis(
13341347
scatterlines!(ax_cl_polar, pd.angle, pd.cl; label=lbl, marker, markersize, color)
13351348
scatterlines!(ax_cd_polar, pd.angle, pd.cd; label=lbl, marker, markersize, color)
13361349
scatterlines!(ax_cs_polar, pd.angle, pd.cs; label=lbl, marker, markersize, color)
1337-
scatterlines!(ax_polar, pd.cd, pd.cl; label=lbl, marker, markersize, color)
1350+
if cl_over_cd
1351+
cl_cd = pd.cl ./ pd.cd
1352+
scatterlines!(ax_fourth_polar, pd.angle, cl_cd;
1353+
label=lbl, marker, markersize, color)
1354+
else
1355+
scatterlines!(ax_fourth_polar, pd.cd, pd.cl;
1356+
label=lbl, marker, markersize, color)
1357+
end
13381358
end
1339-
# axislegend(ax_cl_polar, position=:lt)
1340-
# axislegend(ax_cd_polar, position=:lt)
1341-
axislegend(ax_cs_polar, position=:lb)
1342-
# axislegend(ax_polar, position=:lt)
1359+
Legend(fig[2, 2][3, :], ax_cl_polar;
1360+
orientation=:horizontal, nbanks=2,
1361+
tellwidth=false, tellheight=true)
13431362

13441363
# Set column widths: left column wider for 3x3 grid
13451364
colsize!(fig.layout, 1, Relative(0.6))

0 commit comments

Comments
 (0)