Skip to content

Commit 8699b27

Browse files
committed
Add a Makie extension.
1 parent eae3060 commit 8699b27

3 files changed

Lines changed: 73 additions & 31 deletions

File tree

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ManifoldsBase"
22
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
3+
version = "2.4.0"
34
authors = ["Seth Axen <seth.axen@gmail.com>", "Mateusz Baran <mateuszbaran89@gmail.com>", "Ronny Bergmann <manopt@ronnybergmann.net>", "Antoine Levitt <antoine.levitt@gmail.com>"]
4-
version = "2.3.5"
55

66
[workspace]
77
projects = ["test", "docs", "tutorials"]
@@ -13,19 +13,22 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1414

1515
[weakdeps]
16+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1617
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1718
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
1819
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
1920
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2021

2122
[extensions]
23+
ManifoldsBaseMakieExt = "Makie"
2224
ManifoldsBasePlotsExt = "Plots"
2325
ManifoldsBaseQuaternionsExt = "Quaternions"
2426
ManifoldsBaseRecursiveArrayToolsExt = "RecursiveArrayTools"
2527
ManifoldsBaseStatisticsExt = "Statistics"
2628

2729
[compat]
2830
LinearAlgebra = "1.6"
31+
Makie = "0.24"
2932
Markdown = "1.6"
3033
Plots = "1"
3134
Printf = "1.6"

ext/ManifoldsBaseMakieExt.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
module ManifoldsBaseMakieExt
2+
3+
using ManifoldsBase
4+
using Makie
5+
using Printf: @sprintf
6+
7+
function ManifoldsBase.plot_slope(
8+
x, y; slope = 2, line_base = 0, a = 0, b = 2.0, i = 1, j = length(x),
9+
)
10+
fig = Makie.Figure()
11+
# Setup the log log plot
12+
ax = Makie.Axis(
13+
fig[1, 1];
14+
xscale = log10, yscale = log10, xlabel = "t", ylabel = L"E(t)", title = "Slope plot",
15+
)
16+
# Main error data
17+
Makie.lines!(ax, x, y; label = L"E(t)", linewidth = 3, color = :lightblue)
18+
# Reference slope
19+
s_line = [exp10(line_base + t * slope) for t in log10.(x)]
20+
Makie.lines!(
21+
ax, x, s_line; label = "slope s=$slope",
22+
linestyle = :dash, color = :black, linewidth = 2
23+
)
24+
25+
# Best-fit slope segment if i and j are provided
26+
if (i != 0) && (j != 0)
27+
best_line = [exp10(a + t * b) for t in log10.(x[i:j])]
28+
Makie.lines!(
29+
ax, x[i:j], best_line;
30+
label = "best slope $(@sprintf("%.4f", b))",
31+
color = :blue, linestyle = :dot, linewidth = 2,
32+
)
33+
end
34+
Makie.axislegend(ax; position = :lt)
35+
return fig
36+
end
37+
function ManifoldsBase.plot_check_geodesic(T, N, e_norm, e_pt, e_alpha)
38+
fig = Figure()
39+
ax = Axis(
40+
fig[1, 1];
41+
xlabel = "t", ylabel = "error magnitude", title = "Geodesic checks",
42+
)
43+
# Speed deviation: |‖Xᵢ‖ − mean‖X‖|
44+
Makie.lines!(
45+
ax, T[1:(N - 1)], e_norm;
46+
label = L"|\|X_i\| - \overline{\|X\|}|", linewidth = 3, color = :lightblue
47+
)
48+
# Parallel-transport mismatch (norm): ‖Xᵢ − PT_{i+1→i}(X_{i+1})‖
49+
lines!(
50+
ax, T[1:(N - 2)], e_pt;
51+
label = "PT difference (norm)", linewidth = 3, color = :blue
52+
)
53+
# Parallel-transport mismatch (angle): |1 − cos∠(Xᵢ, PT_{i+1→i}X_{i+1})|
54+
lines!(
55+
ax, T[1:(N - 2)], e_alpha;
56+
label = "PT difference (angle)", linewidth = 3, color = :green
57+
)
58+
axislegend(ax; position = :rt)
59+
return fig
60+
end
61+
end

ext/ManifoldsBasePlotsExt.jl

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,26 @@ module ManifoldsBasePlotsExt
33
using ManifoldsBase
44
using Plots
55
using Printf: @sprintf
6-
import ManifoldsBase: plot_slope
76

87
function ManifoldsBase.plot_slope(
9-
x,
10-
y;
11-
slope = 2,
12-
line_base = 0,
13-
a = 0,
14-
b = 2.0,
15-
i = 1,
16-
j = length(x),
8+
x, y;
9+
slope = 2, line_base = 0, a = 0, b = 2.0, i = 1, j = length(x),
1710
)
1811
fig = plot(
19-
x,
20-
y;
21-
xaxis = :log,
22-
yaxis = :log,
23-
label = "\$E(t)\$",
24-
linewidth = 3,
25-
legend = :topleft,
26-
color = :lightblue,
12+
x, y; xaxis = :log, yaxis = :log, label = "\$E(t)\$",
13+
linewidth = 3, legend = :topleft, color = :lightblue,
2714
)
2815
s_line = [exp10(line_base + t * slope) for t in log10.(x)]
2916
plot!(
30-
fig,
31-
x,
32-
s_line;
33-
label = "slope s=$slope",
34-
linestyle = :dash,
35-
color = :black,
36-
linewidth = 2,
17+
fig, x, s_line; label = "slope s=$slope",
18+
linestyle = :dash, color = :black, linewidth = 2,
3719
)
3820
if (i != 0) && (j != 0)
3921
best_line = [exp10(a + t * b) for t in log10.(x[i:j])]
4022
plot!(
41-
fig,
42-
x[i:j],
43-
best_line;
23+
fig, x[i:j], best_line;
4424
label = "best slope $(@sprintf("%.4f", b))",
45-
color = :blue,
46-
linestyle = :dot,
47-
linewidth = 2,
25+
color = :blue, linestyle = :dot, linewidth = 2,
4826
)
4927
end
5028
return fig

0 commit comments

Comments
 (0)