Skip to content

Commit 103733e

Browse files
authored
Merge pull request #1977 from GenericMappingTools/fix-xvals
Fix the xvals option in labellines
2 parents e6df8d7 + ceeb629 commit 103733e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/legend_funs.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,18 @@ Called from `_common_plot_xyz()` when the `labellines` keyword is used.
814814
function add_labellines!(curves, d::Dict{Symbol,Any}, _cmd::Vector{String})
815815
val = find_in_dict(d, [:labellines])[1]
816816
if isa(val, Vector{<:AbstractString})
817-
_add_labellines(curves, _cmd, [string(l) for l in val], 8, :middle)
817+
labels = [string(l) for l in val]
818+
xv = find_in_dict(d, [:xvals])[1]
819+
yv = find_in_dict(d, [:yvals])[1]
820+
if xv !== nothing || yv !== nothing
821+
nc = length(curves)
822+
_xv = xv === nothing ? Float64[] : isa(xv, Real) ? fill(Float64(xv), nc) : Float64.(collect(xv))
823+
_yv = yv === nothing ? Float64[] : isa(yv, Real) ? fill(Float64(yv), nc) : Float64.(collect(yv))
824+
pos = _label_pos_at_vals(curves, nc, _xv, _yv)
825+
_add_labellines_apply(curves, _cmd, labels, 8, pos)
826+
else
827+
_add_labellines(curves, _cmd, labels, 8, :middle)
828+
end
818829
return curves
819830
end
820831
# NamedTuple path — dispatch to the right inner function based on which options are set

src/utils_types.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ function _mat2ds(@nospecialize(mat::Array{<:Real}), txt::Union{String,Vector{Str
264264
_lts[k] = " -W" * string(_lt[((k % n_thick) != 0) ? k % n_thick : n_thick])
265265
end
266266
else
267-
theW = (color_cycle || haskey(d, :ls) || haskey(d, :linestyle) || haskey(d, :pen)) ? " -W" : ""
267+
theW = (color_cycle || get(d, :ls, nothing) !== nothing || get(d, :linestyle, nothing) !== nothing || get(d, :pen, nothing) !== nothing) ? " -W" : ""
268+
#theW = (color_cycle || haskey(d, :ls) || haskey(d, :linestyle) || haskey(d, :pen)) ? " -W" : ""
268269
_lts = fill(theW, n_ds) # If no pen setting no need to set -W
269270
end
270271

0 commit comments

Comments
 (0)