Merge pull request #2473 from BeastyBlacksmith/pgfplotsx
another legends fix
This commit is contained in:
commit
d04d651e55
@ -346,28 +346,28 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
# add to legend?
|
# add to legend?
|
||||||
if sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
if sp[:legend] != :none
|
||||||
leg_entry = if opt[:label] isa AVec
|
leg_entry = if opt[:label] isa AVec
|
||||||
get(opt[:label], i, "")
|
get(opt[:label], i, "")
|
||||||
elseif opt[:label] isa AbstractString
|
elseif opt[:label] isa AbstractString
|
||||||
if i == 1
|
if i == 1
|
||||||
opt[:label]
|
get(opt, :label, "")
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
throw(ArgumentError("Malformed label. label = $(opt[:label])"))
|
throw(ArgumentError("Malformed label. label = $(opt[:label])"))
|
||||||
end
|
end
|
||||||
if leg_entry == ""
|
if leg_entry == "" || !pgfx_should_add_to_legend(series)
|
||||||
push!(segment_plot.options, "forget plot" => nothing)
|
push!(axis.contents[end].options, "forget plot" => nothing)
|
||||||
continue
|
else
|
||||||
|
leg_opt = PGFPlotsX.Options()
|
||||||
|
if ribbon !== nothing
|
||||||
|
pgfx_filllegend!(axis.contents[end - 3].options, opt)
|
||||||
|
end
|
||||||
|
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
|
||||||
|
push!(axis, legend)
|
||||||
end
|
end
|
||||||
leg_opt = PGFPlotsX.Options()
|
|
||||||
if ribbon !== nothing
|
|
||||||
pgfx_filllegend!(axis.contents[end - 3].options, opt)
|
|
||||||
end
|
|
||||||
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
|
|
||||||
push!(axis, legend)
|
|
||||||
end
|
end
|
||||||
end # for segments
|
end # for segments
|
||||||
# add subplot annotations
|
# add subplot annotations
|
||||||
@ -691,7 +691,7 @@ function pgfx_font(fontsize, thickness_scaling = 1, font = "\\selectfont")
|
|||||||
end
|
end
|
||||||
|
|
||||||
function pgfx_should_add_to_legend(series::Series)
|
function pgfx_should_add_to_legend(series::Series)
|
||||||
series.plotattributes[:primary] && series.plotattributes[:label] != "" &&
|
series.plotattributes[:primary] &&
|
||||||
!(
|
!(
|
||||||
series.plotattributes[:seriestype] in (
|
series.plotattributes[:seriestype] in (
|
||||||
:hexbin,
|
:hexbin,
|
||||||
|
|||||||
@ -20,6 +20,19 @@ end
|
|||||||
@test count(x -> x isa PGFPlotsX.Plot, axis.contents) == 1
|
@test count(x -> x isa PGFPlotsX.Plot, axis.contents) == 1
|
||||||
@test !haskey(axis.contents[1].options.dict, "fill")
|
@test !haskey(axis.contents[1].options.dict, "fill")
|
||||||
|
|
||||||
|
@testset "Legends" begin
|
||||||
|
legends_plot = plot( rand(5,2), lab = ["1" ""] )
|
||||||
|
scatter!(legends_plot, rand(5) )
|
||||||
|
Plots._update_plot_object(legends_plot)
|
||||||
|
axis_contents = Plots.pgfx_axes(legends_plot.o)[1].contents
|
||||||
|
leg_entries = filter( x -> x isa PGFPlotsX.LegendEntry, axis_contents )
|
||||||
|
series = filter( x -> x isa PGFPlotsX.Plot, axis_contents )
|
||||||
|
@test length(leg_entries) == 2
|
||||||
|
@test !haskey(series[1].options.dict, "forget plot")
|
||||||
|
@test haskey(series[2].options.dict, "forget plot")
|
||||||
|
@test !haskey(series[3].options.dict, "forget plot")
|
||||||
|
end # testset
|
||||||
|
|
||||||
@testset "3D docs example" begin
|
@testset "3D docs example" begin
|
||||||
n = 100
|
n = 100
|
||||||
ts = range(0, stop = 8π, length = n)
|
ts = range(0, stop = 8π, length = n)
|
||||||
@ -74,8 +87,18 @@ end
|
|||||||
@test marker.options["mark options"]["line width"] == 1
|
@test marker.options["mark options"]["line width"] == 1
|
||||||
end # testset
|
end # testset
|
||||||
@testset "Plot in pieces" begin
|
@testset "Plot in pieces" begin
|
||||||
plot(rand(100) / 3, reg = true, fill = (0, :green))
|
pic = plot(rand(100) / 3, reg = true, fill = (0, :green))
|
||||||
scatter!(rand(100), markersize = 6, c = :orange)
|
scatter!(pic, rand(100), markersize = 6, c = :orange)
|
||||||
|
Plots._update_plot_object(pic)
|
||||||
|
axis_contents = Plots.pgfx_axes(pic.o)[1].contents
|
||||||
|
leg_entries = filter( x -> x isa PGFPlotsX.LegendEntry, axis_contents )
|
||||||
|
series = filter( x -> x isa PGFPlotsX.Plot, axis_contents )
|
||||||
|
@test length(leg_entries) == 2
|
||||||
|
@test length(series) == 4
|
||||||
|
@test haskey(series[1].options.dict, "forget plot")
|
||||||
|
@test !haskey(series[2].options.dict, "forget plot")
|
||||||
|
@test haskey(series[3].options.dict, "forget plot")
|
||||||
|
@test !haskey(series[4].options.dict, "forget plot")
|
||||||
end # testset
|
end # testset
|
||||||
@testset "Marker types" begin
|
@testset "Marker types" begin
|
||||||
markers = filter((m -> begin
|
markers = filter((m -> begin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user