Skip to content

Commit 46cadf3

Browse files
committed
fix limits for 3D plots with Makie, add viewmode kwarg
1 parent 533e77f commit 46cadf3

File tree

3 files changed

+65
-45
lines changed

3 files changed

+65
-45
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GridVisualize"
22
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
33
authors = ["Juergen Fuhrmann <[email protected]>", "Patrick Jaap <[email protected]>"]
4-
version = "1.11.0"
4+
version = "1.12.0"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

src/dispatch.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ function default_plot_kwargs()
367367
),
368368
:scene3d => Pair(
369369
:Axis3,
370-
"3D plot type of Makie scene. Alternaitve to `:Axis3` is `:LScene`"
370+
"3D plot type of Makie scene. Alternative to `:Axis3` is `:LScene`"
371371
),
372+
:viewmode => Pair(:fit, "Axis3d viewmode for Makie plots. Possible values :fit or :free"),
372373
:fignumber => Pair(1, "Figure number (PyPlot)"),
373374
:framepos => Pair(1, "Subplot position in frame (VTKView)"),
374375
:subplot => Pair((1, 1), "Private: Actual subplot"),
@@ -377,7 +378,7 @@ function default_plot_kwargs()
377378
:regions => Pair(:all, "List of regions to plot"),
378379
:species => Pair(1, "Number of species to plot or number of species in regions"),
379380
:spacing => Pair(nothing, "Removed from API"),
380-
:show_colorbar => Pair(true, "Show color bar next to grid plots"),
381+
:show_colorbar => Pair(true, "Show color bar next to plots"),
381382
:slice => Pair(nothing, "Plot a dim-1 slice along a hyperplane expression :(αx ± βy [± γz] ± δ)) or a fixed axis pair, e.g., :x => 3")
382383
)
383384
end

src/makie.jl

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -670,23 +670,25 @@ function makescene2d(ctx, key)
670670
GL[1, 1] = ctx[:scene]
671671

672672
# , fontsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize]
673-
if ctx[:colorbar] == :vertical
674-
GL[1, 2] = XMakie.Colorbar(
675-
ctx[:figure],
676-
ctx[key];
677-
width = 10,
678-
ticks = unique(ctx[:cbarticks]),
679-
tickformat = "{:.2e}",
680-
)
681-
elseif ctx[:colorbar] == :horizontal
682-
GL[2, 1] = XMakie.Colorbar(
683-
ctx[:figure],
684-
ctx[key];
685-
height = 10,
686-
ticks = unique(ctx[:cbarticks]),
687-
vertical = false,
688-
tickformat = "{:.2e}",
689-
)
673+
if ctx[:show_colorbar]
674+
if ctx[:colorbar] == :vertical
675+
GL[1, 2] = XMakie.Colorbar(
676+
ctx[:figure],
677+
ctx[key];
678+
width = 10,
679+
ticks = unique(ctx[:cbarticks]),
680+
tickformat = "{:.2e}",
681+
)
682+
elseif ctx[:colorbar] == :horizontal
683+
GL[2, 1] = XMakie.Colorbar(
684+
ctx[:figure],
685+
ctx[key];
686+
height = 10,
687+
ticks = unique(ctx[:cbarticks]),
688+
vertical = false,
689+
tickformat = "{:.2e}",
690+
)
691+
end
690692
end
691693
return GL
692694
end
@@ -940,13 +942,17 @@ function makeaxis3d(ctx)
940942
XMakie = ctx[:Plotter]
941943
if ctx[:scene3d] == :LScene
942944
# "Old" LScene with zoom-in functionality
943-
return XMakie.LScene(ctx[:figure])
945+
lim = ctx[:limits]
946+
lim = Observable(Rect3f(Vec3f(lim[1], lim[3], lim[5]), Vec3f(lim[2], lim[4], lim[6])))
947+
scene = XMakie.LScene(ctx[:figure], scenekw = (; limits = lim))
948+
return scene
944949
else
945950
# "New" Axis3 with prospective new stuff by Julius.
946951
return XMakie.Axis3(
947952
ctx[:figure];
948953
aspect = :data,
949-
viewmode = :fit,
954+
viewmode = ctx[:viewmode],
955+
limits = ctx[:limits],
950956
elevation = ctx[:elev] * π / 180,
951957
azimuth = ctx[:azim] * π / 180,
952958
perspectiveness = ctx[:perspectiveness],
@@ -977,31 +983,32 @@ function makescene3d(ctx)
977983
end
978984
GL[1, 1] = ctx[:scene]
979985
# Horizontal or vertical colorbar
980-
if haskey(ctx, :crange)
981-
if ctx[:colorbar] == :vertical
982-
GL[1, 2] = XMakie.Colorbar(
983-
ctx[:figure];
984-
colormap = ctx[:colormap],
985-
colorrange = ctx[:crange],
986-
ticks = map(d -> d.c, ctx[:data]),
987-
tickformat = "{:.2e}",
988-
width = 15,
989-
ticklabelsize = 0.5 * ctx[:fontsize],
990-
)
991-
elseif ctx[:colorbar] == :horizontal
992-
GL[2, 1] = XMakie.Colorbar(
993-
ctx[:figure];
994-
colormap = ctx[:colormap],
995-
colorrange = ctx[:crange],
996-
ticks = map(d -> d.c, ctx[:data]),
997-
tickformat = "{:.2e}",
998-
height = 15,
999-
ticklabelsize = 0.5 * ctx[:fontsize],
1000-
vertical = false,
1001-
)
986+
if ctx[:show_colorbar]
987+
if haskey(ctx, :crange)
988+
if ctx[:colorbar] == :vertical
989+
GL[1, 2] = XMakie.Colorbar(
990+
ctx[:figure];
991+
colormap = ctx[:colormap],
992+
colorrange = ctx[:crange],
993+
ticks = map(d -> d.c, ctx[:data]),
994+
tickformat = "{:.2e}",
995+
width = 15,
996+
ticklabelsize = 0.5 * ctx[:fontsize],
997+
)
998+
elseif ctx[:colorbar] == :horizontal
999+
GL[2, 1] = XMakie.Colorbar(
1000+
ctx[:figure];
1001+
colormap = ctx[:colormap],
1002+
colorrange = ctx[:crange],
1003+
ticks = map(d -> d.c, ctx[:data]),
1004+
tickformat = "{:.2e}",
1005+
height = 15,
1006+
ticklabelsize = 0.5 * ctx[:fontsize],
1007+
vertical = false,
1008+
)
1009+
end
10021010
end
10031011
end
1004-
10051012
# Put the status label into protrusion space on the bottom of the scene
10061013
GL[1, 1, XMakie.Bottom()] = XMakie.Label(
10071014
ctx[:figure],
@@ -1038,6 +1045,11 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid)
10381045
XMakie = ctx[:Plotter]
10391046
xyzmin, xyzmax = xyzminmax(grid, ctx[:gridscale])
10401047
xyzstep = (xyzmax - xyzmin) / 100
1048+
ctx[:limits] = (
1049+
xyzmin[1], xyzmax[1],
1050+
xyzmin[2], xyzmax[2],
1051+
xyzmin[3], xyzmax[3],
1052+
)
10411053

10421054
function adjust_planes(xplane, yplane, zplane)
10431055
ctx[:ixplane] = max(xyzmin[1], min(xyzmax[1], xplane))
@@ -1195,6 +1207,7 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid)
11951207

11961208
ctx[:status] = Observable(" ")
11971209

1210+
XMakie.reset_limits!(ctx[:scene])
11981211
add_scene!(ctx, makescene_grid(ctx))
11991212

12001213
else
@@ -1250,6 +1263,12 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid
12501263
fstep = 0.1
12511264
end
12521265

1266+
ctx[:limits] = (
1267+
xyzmin[1], xyzmax[1],
1268+
xyzmin[2], xyzmax[2],
1269+
xyzmin[3], xyzmax[3],
1270+
)
1271+
12531272
ctx[:ixplanes] = collect(ctx[:xplanes]) * ctx[:gridscale]
12541273
ctx[:iyplanes] = collect(ctx[:yplanes]) * ctx[:gridscale]
12551274
ctx[:izplanes] = collect(ctx[:zplanes]) * ctx[:gridscale]

0 commit comments

Comments
 (0)