Skip to content

Commit 9ab2a9b

Browse files
authored
Fixes in choropleth plot and uses of get_show_fmt_savefig() (#1895)
1 parent f3ef1fd commit 9ab2a9b

6 files changed

Lines changed: 12 additions & 35 deletions

File tree

src/GMT.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ export
174174
geodesic, orthodrome, proj2wkt, setcoords!, setfld!, setcrs!, setsrs!, settimecol!, vecangles, wkt2proj,
175175
inbbox, randgeo,
176176

177-
colorzones!, rasterzones!, rasterzones, lelandshade, texture_img, crop, doy2date, date2doy, fourcolors, yeardecimal,
178-
ISOtime2unix, median, mean, quantile, std, nanmean, nanstd, skipnan, zonal_statistics, zonal_stats,
179-
autocor, autocor!, autocov, autocov!, conv, xcorr, xcov,
177+
colorzones!, rasterzones!, rasterzones, lelandshade, texture_img, crop, doy2date, date2doy, choropleth, fourcolors,
178+
getdcw, ISOtime2unix, median, mean, quantile, std, nanmean, nanstd, skipnan, zonal_statistics, zonal_stats,
179+
autocor, autocor!, autocov, autocov!, conv, yeardecimal, xcorr, xcov,
180180

181181
add2PSfile, append2fig, isoutlier, linearfitxy, regiongeog, streamlines, peaks, polygonlevels, randinpolygon, polyfit, polyval,
182182

src/analemma.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ function _analemma(lon, lat, year, hour, cmap, lonlat::Bool, data::Bool, d)
5555
D = mat2ds(ana)
5656
data && (D.colnames = cnames; return D)
5757

58-
do_show = ((val = find_in_dict(d, [:show])[1]) === nothing) ? true : false # Default is to show
58+
do_show, fmt, savefig = get_show_fmt_savefig(d, true) # Default is to show
5959
C = makecpt(cmap=cmap, range=(1, n_days))
6060
plot(D, marker="c", markersize="4p", cmap=C, zcolor=collect(1:n_days), colorbar=(xlabel="Day of year",),
6161
xlabel= lonlat ? "Longitude" : "Azimuth", ylabel= lonlat ? "Latitude" : "Elevation",
62-
title=@sprintf("Analemma %02d:00 lat=%.1f", floor(Int, hour), lat), show=do_show, d...)
62+
title=@sprintf("Analemma %02d:00 lat=%.1f", floor(Int, hour), lat), fmt=fmt, savefig=savefig, show=do_show, d...)
6363
end
6464

6565
# ---------------------------------------------------------------------------------------------------
@@ -138,9 +138,7 @@ function _sunsetrise(lon, lat, year::Int, TZ::Int, raise::Bool, both::Bool, data
138138
yaxis_nt = (annot=15, annot_unit=:minute2, ticks=5, ticks_unit=:minute2, label=y_label)
139139
par = (FORMAT_DATE_MAP="o", FORMAT_TIME_PRIMARY_MAP="abbreviated")
140140

141-
do_show = ((val = find_in_dict(d, [:show])[1]) === nothing) ? true : false # Default is to show
142-
fmt::String = ((val = find_in_dict(d, [:fmt])[1]) !== nothing) ? arg2str(val)::String : FMT[]::String
143-
savefig = ((val = find_in_dict(d, [:savefig :figname :name])[1]) !== nothing) ? arg2str(val)::String : nothing
141+
do_show, fmt, savefig = get_show_fmt_savefig(d, true) # Default is to show
144142
opt_R = ((val = find_in_dict(d, [:R :region :limits])[1]) !== nothing) ? val : "tightx"
145143
both ? plotyy(Dsr, Dss, yaxis=yaxis_nt, title=title, conf=par, R=opt_R, lw=1; d...) :
146144
plot(Dsun, xaxis=xaxis_nt, yaxis=yaxis_nt, title=title, lc="#0072BD", lw="1p", conf=par, R=opt_R; d...)

src/choropleth.jl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
export choropleth
2-
3-
41
"""
52
choropleth(D, ids, vals; attrib="CODE", cmap="turbo", outline=true, kw...)
63
choropleth(D, att=""; attrib="", cmap="turbo", outline=true, kw...)
@@ -143,14 +140,8 @@ function helper_plot_choropleth(D, ids, vals, attrib::String, cmap, outline, _zv
143140
zvals = (isempty(_zvals)) ? polygonlevels(D, ids, vals, att=attrib) : _zvals
144141
pen_ouline = isa(outline, Bool) ? "0" : outline
145142
C = isa(cmap, GMTcpt) ? cmap : makecpt(T=(minimum(vals), maximum(vals)), C=string(cmap))
146-
plot_outline = (outline != false)
147-
(!plot_outline) && return plot(D; level=zvals, cmap=C, kw...)
148-
d = KW(kw)
149-
do_show, fmt, savefig = get_show_fmt_savefig(d, false)
150-
plot(D; level=zvals, cmap=C)
151-
#plot!(D; pen=pen_ouline, fmt=fmt, savefig=savefig, show=do_show, d...)
152-
d[:fmt]=fmt; d[:savefig]=savefig; d[:show]=do_show; d[:pen]=pen_ouline
153-
common_plot_xyz("", D, "plot", false, false, d)
143+
return (outline != false) ? plot(D; level=zvals, cmap=C, plot=(data=D, pen=pen_ouline), kw...) :
144+
plot(D; level=zvals, cmap=C, kw...)
154145
end
155146

156147
# ------------------------------------------------------------------------------------------------------

src/getdcw.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export getdcw
2-
31
"""
42
getdcw(codes; states=false, file::StrSymb="") -> Vector{GMTdataset}
53

src/gmtlogo.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,8 @@ function logo(cmd0::String=""; first=true, kwargs...)
5555
c,t,r2 = jlogo(r) # r2 is the diameter of the inner circle
5656
if (!occursin("-R", cmd)) cmd = @sprintf("-R0/%f/0/%f ", 2r, 2r) * cmd end
5757
if (!occursin("-J", cmd)) cmd = " -Jx1 " * cmd end
58-
do_show = false
59-
if (do_GMTjulia)
60-
do_show = ((val = find_in_dict(d, [:show])[1]) !== nothing && val != 0) # Too soon
61-
end
62-
fmt::AbstractString = ""
63-
if (do_GMTjulia)
64-
# Too soon to set the format. Need to finish the PS first
65-
((val = find_in_dict(d, [:fmt])[1]) !== nothing) && (fmt = arg2str(val))
66-
savefig::AbstractString = ""
67-
if ((val = find_in_dict(d, [:savefig :name :figname])[1]) !== nothing) # Also too early for savefig
68-
savefig = val
69-
end
58+
if (do_GMTjulia) # Too soon to use the show, fmt, ...
59+
do_show, fmt, savefig = get_show_fmt_savefig(d, true) # Default is to show
7060
end
7161
cmd = "psxy " * c * cmd
7262
((_r = check_dbg_print_cmd(d, cmd)) !== nothing && startswith(_r, "psxy")) && return _r

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,9 +1761,9 @@ in the last plotting comand. Centralise those options fetching in this function.
17611761
"""
17621762
function get_show_fmt_savefig(d, show::Bool=false)
17631763
# 'show' carries the default of the caller for the show-or-not-show
1764-
do_show = ((val = find_in_dict(d, [:show])[1]) === nothing) ? show : !show
1764+
do_show::Bool = ((val = find_in_dict(d, [:show])[1]) === nothing) ? show : (val == 1)
17651765
fmt::String = ((val = find_in_dict(d, [:fmt])[1]) !== nothing) ? arg2str(val)::String : FMT[]::String
1766-
savefig = ((val = find_in_dict(d, [:savefig :figname :name])[1]) !== nothing) ? arg2str(val)::String : nothing
1766+
savefig::Union{String,Nothing} = ((val = find_in_dict(d, [:savefig :figname :name])[1]) !== nothing) ? arg2str(val)::String : nothing
17671767
return do_show, fmt, savefig
17681768
end
17691769

0 commit comments

Comments
 (0)