Skip to content

Commit 72f8677

Browse files
authored
Add :symlog axis scaling option (#113)
1 parent 13db741 commit 72f8677

7 files changed

Lines changed: 47 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.17.0] - 2026-01-09
4+
- Add `:symlog` axis scaling for symmetric logarithmic axis scaling, see, e.g. [matplotlib symlog](https://matplotlib.org/stable/gallery/scales/symlog_demo.html)
5+
- Add `:symlog_threshold` (default = 10.0) to determine when to switch from linear to log scaling in case of `:symlog` scaling
6+
37
## [1.16.3] - 2026-01-07
48
- Add `title`, `xlabel`, and `ylabel` to 1D and 2D `gridplot!` with `GLMakie`
59
- Add `title`, `xlabel`, and `ylabel` to 1D and 2D `gridplot!` with `Py[thon]Plot`

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 <juergen.fuhrmann@wias-berlin.de>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
4-
version = "1.16.3"
4+
version = "1.17.0"
55

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

ext/GridVisualizeMakieExt.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,28 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grids, parentgrid
474474
if !haskey(ctx, :scene)
475475
ctx[:xtitle] = Observable(ctx[:title])
476476

477+
if ctx[:xscale] == :log
478+
xscale = log10
479+
elseif ctx[:xscale] == :symlog
480+
xscale = XMakie.Makie.Makie.Symlog10(ctx[:symlog_threshold])
481+
else
482+
xscale = identity
483+
end
484+
485+
if ctx[:yscale] == :log
486+
yscale = log10
487+
elseif ctx[:yscale] == :symlog
488+
yscale = XMakie.Makie.Makie.Symlog10(ctx[:symlog_threshold])
489+
else
490+
yscale = identity
491+
end
492+
477493
# Axis
478494
ctx[:scene] = XMakie.Axis(
479495
ctx[:figure];
480496
title = map(a -> a, ctx[:xtitle]),
481-
xscale = ctx[:xscale] == :log ? log10 : identity,
482-
yscale = ctx[:yscale] == :log ? log10 : identity,
497+
xscale,
498+
yscale,
483499
xlabel = ctx[:xlabel],
484500
ylabel = ctx[:ylabel],
485501
scenekwargs(ctx)...,

ext/GridVisualizePlotsExt.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ function scalarplot!(ctx, TP::Type{PlotsType}, ::Type{Val{1}}, grids, parentgrid
260260
ymax = ylimits[2]
261261
end
262262

263+
for key in (:xscale, :yscale)
264+
if ctx[key] == :symlog
265+
@warn "Plots.jl does not support symlog axis scaling for $key."
266+
ctx[key] = :identity
267+
end
268+
end
269+
263270
ctx[:xscale] == :log ? ctx[:xscale] = :log10 : nothing
264271
ctx[:yscale] == :log ? ctx[:yscale] = :log10 : nothing
265272

ext/GridVisualizePlutoVistaExt.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ function scalarplot!(
221221
PlutoVista = ctx[:Plotter]
222222
PlutoVista.backend!(ctx[:figure]; backend = ctx[:backend], datadim = 1)
223223

224+
for key in (:xscale, :yscale)
225+
if ctx[key] == :symlog
226+
@warn "Plutovista.jl does not support symlog axis scaling for $key."
227+
ctx[key] = :identity
228+
end
229+
end
230+
224231
for ifunc in 1:nfuncs
225232
func = funcs[ifunc]
226233
grid = grids[ifunc]

src/dispatch.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ function default_plot_kwargs()
386386
:spacing => Pair(nothing, "Removed from API"),
387387
:species => Pair(1, "Number of species to plot or number of species in regions"),
388388
:subplot => Pair((1, 1), "Private: Actual subplot"),
389+
:symlog_threshold => Pair(10.0, ":symlog threshold for switching from linear to log scaling. Only relevant for :symlog axis scaling."),
389390
:title => Pair("", "Plot title"),
390391
:tetxplane_tol => Pair(0.0, "tolerance for tet-plane intersection in 3D"),
391392
:vconstant => Pair(false, "Set all arrow length constant in vector plot"),
@@ -395,11 +396,11 @@ function default_plot_kwargs()
395396
:xlimits => Pair((1, -1), "x axis limits"),
396397
:xplanes => Pair([prevfloat(Inf)], "3D x plane positions or number thereof"),
397398
:xlabel => Pair("x", "x axis label"),
398-
:xscale => Pair(:identity, "x axis scale: one of [:log, :identity]"),
399+
:xscale => Pair(:identity, "x axis scale: one of [:log, :identity, :symlog]"),
399400
:ylimits => Pair((1, -1), "y axis limits"),
400401
:ylabel => Pair("y", "y axis label"),
401402
:yplanes => Pair([prevfloat(Inf)], "3D y plane positions or number thereof"),
402-
:yscale => Pair(:identity, "y axis scale: one of [:log, :identity]"),
403+
:yscale => Pair(:identity, "y axis scale: one of [:log, :identity, :symlog]"),
403404
:zlimits => Pair((1, -1), "z axis limits"),
404405
:zplanes => Pair([prevfloat(Inf)], "3D z plane positions or number thereof"),
405406
:zlabel => Pair("z", "z axis label"),

src/pycommon.jl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,14 @@ function scalarplot!(ctx, TP::Type{T}, ::Type{Val{1}}, grids, parentgrid, funcs)
436436
ax = ctx[:ax]
437437
fig = ctx[:figure]
438438

439+
# activate log scaling
440+
ctx[:xscale] == :log && ax.set_xscale("log")
441+
ctx[:xscale] == :symlog && ax.set_xscale("symlog", linthresh = ctx[:symlog_threshold])
442+
ctx[:yscale] == :log && ax.set_yscale("log")
443+
ctx[:yscale] == :symlog && ax.set_yscale("symlog", linthresh = ctx[:symlog_threshold])
444+
439445
pplot = ax.plot
440-
if ctx[:xscale] == :log
441-
if ctx[:yscale] == :log
442-
pplot = ax.loglog
443-
else
444-
pplot = ax.semilogx
445-
end
446-
end
447-
if ctx[:yscale] == :log
448-
if ctx[:xscale] == :log
449-
pplot = ax.loglog
450-
else
451-
pplot = ax.semilogy
452-
end
453-
end
446+
454447
gridscale = ctx[:gridscale]
455448
if ctx[:cellwise] # not checked, outdated
456449
for icell in 1:num_cells(grid)

0 commit comments

Comments
 (0)