From 45064fad9d2ed8c80288424190446ed9b1454cd2 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Wed, 13 Aug 2025 11:06:58 +0200 Subject: [PATCH 1/2] update ppt_MakieConfig - to widescreen (13.3inch) - producing svg by default save_with_config now return abolute path that allows ctrl-click open in vscode note that png_MakieConfig uses the now default Makie px_per_unit=2.0, so that pngs (or copies from previewer) need to be rescaled to 50% in presentation (better quality during presentation) --- docs/src/makie.md | 5 ++- ext/FigureHelpersMakieExt.jl | 12 ++---- src/FigureHelpers.jl | 4 +- src/makie_util.jl | 81 +++++++++++++++++++++++++++--------- test/test_cairomakie.jl | 27 +++++++++++- 5 files changed, 95 insertions(+), 34 deletions(-) diff --git a/docs/src/makie.md b/docs/src/makie.md index 541d1ef..42877d8 100644 --- a/docs/src/makie.md +++ b/docs/src/makie.md @@ -25,15 +25,16 @@ properties such as figure sizes, fontsizes, and graphics format. The following class helps to collect them and provide them to functions below ```@docs MakieConfig +paper_MakieConfig ``` -### creating figures with adjusted sizes and font-sizes +### creating Makie Figures with adjusted sizes and font-sizes ```@docs figure_conf figure_conf_axis ``` -### saving figures to correct format and dpi-resolution +### saving figures to correct format, subdirectory, and dpi-resolution ```@docs save_with_config diff --git a/ext/FigureHelpersMakieExt.jl b/ext/FigureHelpersMakieExt.jl index 8c44b6c..3747f4d 100644 --- a/ext/FigureHelpersMakieExt.jl +++ b/ext/FigureHelpersMakieExt.jl @@ -15,13 +15,6 @@ function CP.figure_conf_axis(args...; makie_config::MakieConfig = MakieConfig(), fig, Axis(fig[1,1]; kwargs...) end -function get_size_from_config(cfg) - 72 .* cfg.size_inches ./ cfg.pt_per_unit # size_pt -end -function get_fontsize_from_config(cfg) - cfg.fontsize ./ cfg.pt_per_unit -end - function CP.figure_conf(; makie_config::MakieConfig = MakieConfig()) size = get_size_from_config(makie_config) fontsize = get_fontsize_from_config(makie_config) @@ -48,8 +41,9 @@ function CP.save_with_config(filename::AbstractString, fig::Union{Figure, Makie. filename_cfg = joinpath(dir,bname) mkpath(dir) #save(filename_cfg, fig, args...) - save(filename_cfg, fig, args...; pt_per_unit = makie_config.pt_per_unit) - filename_cfg + save(filename_cfg, fig, args...; + pt_per_unit = makie_config.pt_per_unit, px_per_unit = makie_config.px_per_unit) + abspath(filename_cfg) end CP.hidexdecoration!(ax; label = false, ticklabels = false, ticks = false, grid = false, minorgrid = false, minorticks = false, kwargs...) = hidexdecorations!(ax; label, ticklabels, ticks, grid, minorgrid, minorticks, kwargs...) diff --git a/src/FigureHelpers.jl b/src/FigureHelpers.jl index 31154fb..f44f45d 100644 --- a/src/FigureHelpers.jl +++ b/src/FigureHelpers.jl @@ -7,8 +7,10 @@ include("util.jl") include("makie_util.jl") export cm_per_inch, cm2inch, golden_ratio, MakieConfig -export figure_conf, figure_conf_axis, save_with_config, ppt_MakieConfig, paper_MakieConfig +export figure_conf, figure_conf_axis, save_with_config +export ppt_MakieConfig, paper_MakieConfig, png_MakieConfig export hidexdecoration!, hideydecoration!, axis_contents +export get_size_from_config, get_fontsize_from_config include("aog_util.jl") export set_default_AoGTheme!, draw_with_legend! diff --git a/src/makie_util.jl b/src/makie_util.jl index a3acd0e..a211553 100644 --- a/src/makie_util.jl +++ b/src/makie_util.jl @@ -30,29 +30,23 @@ const golden_ratio = 1.618 A collection of figure properties to tailor the same figure either for presentation in a paper or a presentation. - ppt_MakieConfig(; - target = :presentation, - filetype = "png", - fontsize=18, - size_inches = (5.0,5.0/golden_ratio), - kwargs...) - - paper_MakieConfig(; - size_inches = cm2inch.((8.3,8.3/golden_ratio)), - kwargs...) - Properties and defaults - `pt_per_unit = 0.75` -- `filetype = "png"` +- `px_per_unit = 2.0` +- `filetype = "svg"` - `fontsize = 9` (point units) - `size_inches = cm2inch.((17.5,17.5/golden_ratio))` (witdth x height) + +The default `px_per_unit` needs to rescale a png image in ppt to 50%, but +this gives better quality. """ @with_kw struct MakieConfig{FT,IT} - target::Symbol = :paper - pt_per_unit::FT = 0.75 - filetype::String = "png" + target::Symbol = :tmp + pt_per_unit::FT = 0.75 # Makie default + px_per_unit::FT = 2.0 # Makie default is 2.0, but control here + filetype::String = "svg" fontsize::IT = 9 - size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio)) + size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio)) # BG-two-collumn end # function MakieConfig(cfg::MakieConfig; @@ -65,16 +59,63 @@ end # MakieConfig(target, pt_per_unit, filetype, fontsize, size_inches) # end +""" +Get the size in pixel from Config, taking care of pt_per_unit and dpi of +""" +function get_size_from_config(cfg; dpi=72) + dpi .* cfg.size_inches ./ cfg.pt_per_unit # size_pt for 72 dpi +end + +function get_fontsize_from_config(cfg) + cfg.fontsize ./ cfg.pt_per_unit +end + + + #ppt_MakieConfig(;target = :presentation, pt_per_unit = 0.75/2, filetype = "png", fontsize=18, size_inches = cm2inch.((29,29/golden_ratio)), kwargs...) = MakieConfig(;target, pt_per_unit, filetype, fontsize, size_inches, kwargs...) # size so that orginal size covers half a wide landscape slide of 33cm # svg does not work properly with fonts in ppt/wps #ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = cm2inch.((16,16/golden_ratio)), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) -# target of 10inch wide screen slide -ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = (5.0,5.0/golden_ratio), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) +# target of 10inch wide screen slide (16:10) +#ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = (5.0,5.0/golden_ratio), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) +# target of 13.3inch wide screen slide (16:9): wide screen +""" + paper_MakieConfig(; + target = :paper, filetype = "pdf", + fontsize=9, size_inches = cm2inch.((8.3,8.3/golden_ratio)), ...) + + ppt_MakieConfig(; + target = :presentation, filetype = "svg", + fontsize=18, size_inches = (6.65,6.65/golden_ratio), ...) -paper_MakieConfig(;size_inches = cm2inch.((8.3,8.3/golden_ratio)), filetype = "pdf", kwargs...) = MakieConfig(;size_inches, filetype, kwargs...) + png_MakieConfig(;target = :png, filetype = "png", ...) + +Specialized configurations adapted to +- `paper_MakieConfig`: single column Biogeosciences paper (8.3cm) +- `ppt_MakieConfig`: half of a wide-screen ppt presentation (13.3 inch), either svg or png + Inserting generated svg yields better quality than copy (=png) from VScode preview. +- `png_MakieConfig`: same as ppt, but generating png images at 200% scale + By default, need to rescale the png to 50% when inserting into presentation. +""" +function paper_MakieConfig(; + target = :paper, filetype = "pdf", + fontsize=9, size_inches = cm2inch.((8.3,8.3/golden_ratio)), + kwargs... + ) + MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) +end; +function ppt_MakieConfig(; + target = :presentation, filetype = "svg", + fontsize=18, size_inches = (6.65,6.65/golden_ratio), + kwargs... + ) + MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) +end; +function png_MakieConfig(;target = :png, filetype = "png", kwargs...) + ppt_MakieConfig(;target, filetype) +end """ figure_conf(; makie_config) @@ -110,7 +151,7 @@ function figure_conf_axis end; Save figure with file updated extension `cfg.filetype` to subdirectory `cfg.filetype` of given path of filename. -Sets `pt_per_unit` to `makie_config.pt_per_unit`. +Sets `pt_per_unit` and `px_per_unit` according to `makie_config`. """ function save_with_config end diff --git a/test/test_cairomakie.jl b/test/test_cairomakie.jl index b6a233f..4231fce 100644 --- a/test/test_cairomakie.jl +++ b/test/test_cairomakie.jl @@ -20,8 +20,8 @@ using CairoMakie fig0 = figure_conf(; makie_config = ppt_MakieConfig()) (x0,y0) = size(fig0.scene) fig = figure_conf(0.5, 1.2; makie_config = ppt_MakieConfig()) - @test size(fig.scene)[1] ≈ x0*1.2 - @test size(fig.scene)[2] ≈ x0*1.2/0.5 + @test size(fig.scene)[1] ≈ x0*1.2 atol=1.0 + @test size(fig.scene)[2] ≈ x0*1.2/0.5 atol=1.0 # makie_config = MakieConfig(filetype="png", target=:presentation) # set_default_CMTheme!(;makie_config) # aog-specific @@ -43,6 +43,29 @@ using CairoMakie # end; +check_pdf_size = () -> begin + makie_config = paper_MakieConfig() + fig = figure_conf(golden_ratio;makie_config); + data = cumsum(randn(4, 101), dims = 2) + series!(Axis(fig[1,1]), data, labels=["label $i" for i in 1:4]) + save_with_config("tmp/tmp", fig; makie_config) + makie_config.size_inches + # load file and check property figure size-inces +end + +check_ppt_png_size = () -> begin + makie_config = png_MakieConfig() + fig = figure_conf(golden_ratio;makie_config); + data = cumsum(randn(4, 101), dims = 2) + series!(Axis(fig[1,1]), data, labels=["label $i" for i in 1:4]) + save_with_config("tmp/tmp", fig; makie_config) + makie_config.size_inches + # load files and check property figure size-inces is 2 times the inces + # + save_with_config("tmp/tmp", fig; makie_config=MakieConfig(makie_config; filetype="svg")) +end + + i_test_larger_margins = () -> begin makie_config = ppt_MakieConfig(filetype="png") set_default_CMTheme!(;makie_config) From 094dcf860da0db0e591865c39b4b4ea4f6e2a2a8 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Wed, 13 Aug 2025 11:23:15 +0200 Subject: [PATCH 2/2] typos --- .github/workflows/SpellCheck.yml | 14 ++++++++++++++ _typos.toml | 2 ++ docs/src/makie.md | 2 +- ext/FigureHelpersMakieAbstractMCMCExt.jl | 2 +- src/aog_util.jl | 2 +- src/makie_util.jl | 8 ++++---- src/util.jl | 2 +- 7 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/SpellCheck.yml create mode 100644 _typos.toml diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml new file mode 100644 index 0000000..3c2bfb6 --- /dev/null +++ b/.github/workflows/SpellCheck.yml @@ -0,0 +1,14 @@ +name: Spell Check + +on: [pull_request] + +jobs: + typos-check: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v4 + - name: Check spelling + uses: crate-ci/typos@master + \ No newline at end of file diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..3e2ef71 --- /dev/null +++ b/_typos.toml @@ -0,0 +1,2 @@ +[default.extend-words] +Missings = "Missings" diff --git a/docs/src/makie.md b/docs/src/makie.md index 42877d8..190f6a6 100644 --- a/docs/src/makie.md +++ b/docs/src/makie.md @@ -10,7 +10,7 @@ The following function help to convert. cm2inch ``` -Figures often look well, if the ratio between length and hight corresponds +Figures often look well, if the ratio between length and height corresponds to the [Golden ratio](https://en.wikipedia.org/wiki/Golden_ratio). So we provide it here. diff --git a/ext/FigureHelpersMakieAbstractMCMCExt.jl b/ext/FigureHelpersMakieAbstractMCMCExt.jl index a4b5961..e02cd91 100644 --- a/ext/FigureHelpersMakieAbstractMCMCExt.jl +++ b/ext/FigureHelpersMakieAbstractMCMCExt.jl @@ -129,7 +129,7 @@ end """ Histogram of several variables of a 3D array, i.e. MCMCChain. -The desnity plot may give wrong impressions, if probability mass is concentrated +The density plot may give wrong impressions, if probability mass is concentrated at the borders, which can be inspected by plotting histograms instead. """ function CP.histogram_params(chns, pars=names(chns, :parameters); diff --git a/src/aog_util.jl b/src/aog_util.jl index 3315bfd..2afaafa 100644 --- a/src/aog_util.jl +++ b/src/aog_util.jl @@ -5,7 +5,7 @@ Setting sensible defaults with taking care of `pt_per_unit` in MakieConfig. When saving png, there is a difference in size between the produced figure in print and display on a monitor and its dpi settings. -This routine adjusts several seetings given in inch by deviding `makie_config.pt_per_unit`. +This routine adjusts several settings given in inch by dividing `makie_config.pt_per_unit`. """ function set_default_AoGTheme! end diff --git a/src/makie_util.jl b/src/makie_util.jl index a211553..11a934d 100644 --- a/src/makie_util.jl +++ b/src/makie_util.jl @@ -35,7 +35,7 @@ Properties and defaults - `px_per_unit = 2.0` - `filetype = "svg"` - `fontsize = 9` (point units) -- `size_inches = cm2inch.((17.5,17.5/golden_ratio))` (witdth x height) +- `size_inches = cm2inch.((17.5,17.5/golden_ratio))` (width x height) The default `px_per_unit` needs to rescale a png image in ppt to 50%, but this gives better quality. @@ -46,7 +46,7 @@ this gives better quality. px_per_unit::FT = 2.0 # Makie default is 2.0, but control here filetype::String = "svg" fontsize::IT = 9 - size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio)) # BG-two-collumn + size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio)) # BG-two-column end # function MakieConfig(cfg::MakieConfig; @@ -75,7 +75,7 @@ end #ppt_MakieConfig(;target = :presentation, pt_per_unit = 0.75/2, filetype = "png", fontsize=18, size_inches = cm2inch.((29,29/golden_ratio)), kwargs...) = MakieConfig(;target, pt_per_unit, filetype, fontsize, size_inches, kwargs...) -# size so that orginal size covers half a wide landscape slide of 33cm +# size so that original size covers half a wide landscape slide of 33cm # svg does not work properly with fonts in ppt/wps #ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = cm2inch.((16,16/golden_ratio)), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...) # target of 10inch wide screen slide (16:10) @@ -132,7 +132,7 @@ the default x-width. The last constructor sets the properties without referring to a config. It uses by default `pt_per_unit=0.75` to conform to png display and save. -Remember to devide fontsize and other sizes specified elsewhere by this factor. +Remember to divide fontsize and other sizes specified elsewhere by this factor. See also [`cm2inch`](@ref) and `save`. """ function figure_conf end; diff --git a/src/util.jl b/src/util.jl index ea82a05..e067b57 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1,5 +1,5 @@ # used in Extensions to pass limimits -"similar to passmissing, creates a function that retuns nothing, if any of its arguments is noting." +"similar to passmissing, creates a function that returns nothing, if any of its arguments is noting." passnothing(f) = (xs...; kwargs...) -> any(isnothing, xs) ? nothing : f(xs...;kwargs...) # function _getindex_keep(ax::CA.AbstractAxis, syms::NTuple{N,Symbol}) where N