Skip to content

Commit 84f6995

Browse files
committed
Use xunit, yunit kwargs better; make guide=nothing produce no label at all
1 parent 27145df commit 84f6995

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

ext/UnitfulExt.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,20 @@ end
2929

3030
function fixaxis!(attr, x, axisletter)
3131
# Attribute keys
32-
axislabel = Symbol(axisletter, :guide) # xguide, yguide, zguide
33-
axislims = Symbol(axisletter, :lims) # xlims, ylims, zlims
34-
axisticks = Symbol(axisletter, :ticks) # xticks, yticks, zticks
3532
err = Symbol(axisletter, :error) # xerror, yerror, zerror
3633
axisunit = Symbol(axisletter, :unit) # xunit, yunit, zunit
3734
axis = Symbol(axisletter, :axis) # xaxis, yaxis, zaxis
38-
u = get!(attr, axisunit, _unit(eltype(x))) # get the unit
39-
# if the subplot already exists with data, use that unit instead
35+
# if the subplot already exists with data, use that unit
4036
sp = get(attr, :subplot, 1)
41-
if sp length(attr[:plot_object]) && attr[:plot_object].n > 0
37+
if sp length(attr[:plot_object])
4238
spu = getaxisunit(attr[:plot_object][sp][axis])
4339
if !isnothing(spu)
4440
u = spu
41+
else # Subplot exists but doesn't have a unit yet
42+
u = get!(attr, axisunit, _unit(eltype(x))) # get the unit
4543
end
46-
attr[axisunit] = u # update the unit in the attributes
44+
else # Subplot doesn't exist yet, so create it with given unit
45+
u = get!(attr, axisunit, _unit(eltype(x))) # get the unit
4746
end
4847
# fix the attributes: labels, lims, ticks, marker/line stuff, etc.
4948
ustripattribute!(attr, err, u)

src/axes.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ function attr!(axis::Axis, args...; kw...)
9595
plotattributes[k] = (Dates.value(v[1]), Dates.value(v[2]))
9696
elseif k === :guide && v isa AbstractString && isempty(v)
9797
plotattributes[k] = protectedstring(v)
98+
elseif k === :unit
99+
if !isnothing(plotattributes[k]) && plotattributes[k] != v
100+
@warn "Overriding unit for $(axis[:letter]) axis: $(plotattributes[k]) -> $v. This will produce a plot, but series plotted before the override cannot update and will therefore be incorrectly treated as if they had the new units."
101+
end
102+
plotattributes[k] = v
98103
else
99104
plotattributes[k] = v
100105
end
@@ -114,7 +119,9 @@ Base.show(io::IO, axis::Axis) = dumpdict(io, axis.plotattributes, "Axis")
114119
ignorenan_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax))
115120

116121
function get_guide(axis::Axis)
117-
if isnothing(axis[:unit]) || axis[:guide] isa ProtectedString ||
122+
if isnothing(axis[:guide])
123+
return ""
124+
elseif isnothing(axis[:unit]) || axis[:guide] isa ProtectedString ||
118125
axis[:unitformat] == :none
119126
return axis[:guide]
120127
else

src/layouts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ function twin(sp, letter)
664664
tax[:grid] = false
665665
tax[:showaxis] = false
666666
tax[:ticks] = :none
667-
tax[:unitformat] = :none
668667
tax[:unit] = orig_sp[get_attr_symbol(letter, :axis)][:unit]
668+
tax[:guide] = nothing
669669
oax[:grid] = false
670670
oax[:mirror] = true
671671
twin_sp[:background_color_inside] = RGBA{Float64}(0, 0, 0, 0)

0 commit comments

Comments
 (0)