11export montage
22
3- # This file was initially created by Claude and still needs lots of cleanings.
4-
3+ # This file was initially created by Claude and still needs to be worked on.
54
65# ------------------------------------------------------------------------------------------
76"""
@@ -21,7 +20,6 @@ Display multiple images arranged in a grid using GMT's subplot.
2120- `frame`: Frame setting for panels. Default: :none
2221- `indices`: Vector of indices selecting which images to display.
2322- `show`: Display the result. Default: true.
24- - `savefig`: Filename to save the montage.
2523
2624### Example
2725```julia
@@ -36,40 +34,39 @@ montage(imgs, grid=(2,3), titles=["A","B","C","D","E","F"], panels_size=5)
3634montage(rand(UInt8, 64, 64, 9), grid=(3,3), margin="0.2c")
3735```
3836"""
39- function montage (images; grid= nothing , panels_size= nothing , margin= " 0.0c " ,
40- title= nothing , titles= nothing , frame= nothing , indices= nothing ,
41- show:: Bool = true , noR:: Bool = false , kw... )
37+ function montage (images; grid= nothing , panels_size= nothing , margin= " -0.23c " ,
38+ title= nothing , titles= nothing , frame= nothing , indices= nothing ,
39+ show:: Bool = true , noR:: Bool = false , kw... )
4240
4341 (indices != = nothing ) && (images = images[indices]) # Apply indices selection
4442 ((n = length (images)) == 0 ) && error (" No images to display" )
4543 nrows, ncols = _montage_grid_size (n, grid) # Calculate grid dimensions
4644
47- subplot_kw = KW (kw)
48- subplot_kw[:grid ] = (nrows, ncols)
49- subplot_kw[:margin ] = margin
50- subplot_kw[:frame ] = frame
51- (frame === nothing ) && (subplot_kw[:D ] = true ) # No frames around panels
52- (title != = nothing ) && (subplot_kw[:title ] = title)
53- subplot_kw[:Vd ] = 1
54-
55- if panels_size != = nothing
56- subplot_kw[:panels_size ] = panels_size
57- else # Auto size based on grid
58- ps = max (3 , min (8 , 18 / max (nrows, ncols)))
59- subplot_kw[:panels_size ] = ps
60- end
45+ d = KW (kw)
46+ d[:grid ] = (nrows, ncols)
47+ d[:margin ] = margin
48+ (frame == " 0" ) ? (d[:par ] = (MAP_FRAME_PEN= " 0" ,); d[:frame ] = frame) :
49+ ((frame != = nothing ) && (d[:B ] = " 0" ; d[:par ] = (:MAP_FRAME_PEN ,parse_pen (frame))))
50+
51+ (frame === nothing ) && (d[:D ] = true ) # No frames around panels
52+ (title != = nothing ) && (d[:title ] = title)
53+
54+ ps = (panels_size != = nothing ) ? panels_size : max (3 , min (8 , 18 / max (nrows, ncols)))
55+ d[:panels_size ] = ps
56+ Vd = get (d, :Vd , 0 ) # Get the Vd option that will be consumed by subplot\
6157
62- subplot (" " , false , subplot_kw ) # Create subplot (since we already have the Dict pass it directly)
58+ subplot (" " , false , d ) # Create subplot (since we already have the Dict pass it directly)
6359 d = CTRL. pocket_d[1 ] # Fetch options not consumed by subplot.
6460
6561 # Plot each ... input
66- k = 0
62+ d[:J ] = " x?"
63+ k = 0 ; n_inputs = length (images)
6764 for row in 1 : nrows
6865 for col in 1 : ncols
69- k += 1
66+ (( k += 1 ) > n_inputs) && break
7067 panel_title = (titles != = nothing && k <= length (titles)) ? titles[k] : nothing
7168 opt_R = isa (images[k], GItype) ? (noR ? " " : getR (images[k])) : " "
72- viz (images[k], panel= (row, col), title= panel_title, R= (opt_R != = " " ? opt_R : nothing ), Vd= 1 , show= false , d... )
69+ viz (images[k]; panel= (row, col), title= panel_title, R= (opt_R != = " " ? opt_R : nothing ), Vd= Vd , show= false , d... )
7370 end
7471 end
7572 subplot (show ? :show : :end ) # End subplot
@@ -78,6 +75,7 @@ function montage(images; grid=nothing, panels_size=nothing, margin="0.0c",
7875end
7976
8077# Calculate grid dimensions
78+ # ----------------------------------------------------------------------------------------------------------
8179function _montage_grid_size (n, size)
8280 if size === nothing || all (x -> x === nothing || x == 0 || (isa (x, AbstractFloat) && isnan (x)), size)
8381 ncols = ceil (Int, sqrt (n))
0 commit comments