use RecipesBase approach
This commit is contained in:
parent
18c9edfe44
commit
b8a1efc4c0
@ -55,6 +55,18 @@ end
|
||||
|
||||
|
||||
## Preprocessing attributes
|
||||
function RecipesPipeline.preprocess_axis_args!(plt::Plot, plotattributes, letter)
|
||||
# Fix letter for seriestypes that are x only but data gets passed as y
|
||||
if get(plotattributes, :seriestype, :path) in
|
||||
(:vline, :vspan, :histogram, :barhist, :stephist, :scatterhist)
|
||||
if get(plotattributes, :orientation, :vertical) == :vertical
|
||||
letter = :x
|
||||
end
|
||||
end
|
||||
|
||||
plotattributes[:letter] = letter
|
||||
RecipesPipeline.preprocess_axis_args!(plt, plotattributes)
|
||||
end
|
||||
|
||||
RecipesPipeline.preprocess_attributes!(plt::Plot, plotattributes) =
|
||||
RecipesPipeline.preprocess_attributes!(plotattributes) # in src/args.jl
|
||||
|
||||
@ -164,15 +164,6 @@ end
|
||||
# a list of series KW dicts.
|
||||
# note: at entry, we only have those preprocessed args which were passed in... no default values yet
|
||||
function _plot!(plt::Plot, plotattributes, args)
|
||||
# swap x and y for seriestypes that are x only
|
||||
if get(plotattributes, :seriestype, :path) in
|
||||
(:vline, :vspan, :histogram, :barhist, :stephist, :scatterhist)
|
||||
if get(plotattributes, :orientation, :vertical) == :vertical
|
||||
@assert length(args) == 1
|
||||
args = (args[1], [])
|
||||
end
|
||||
end
|
||||
|
||||
RecipesPipeline.recipe_pipeline!(plt, plotattributes, args)
|
||||
current(plt)
|
||||
_do_plot_show(plt, plt[:show])
|
||||
|
||||
@ -764,7 +764,7 @@ end
|
||||
|
||||
@recipe function f(::Type{Val{:barhist}}, x, y, z)
|
||||
h = _make_hist(
|
||||
tuple(plotattributes[:orientation] == :horizontal ? y : x),
|
||||
tuple(y),
|
||||
plotattributes[:bins],
|
||||
normed = plotattributes[:normalize],
|
||||
weights = plotattributes[:weights],
|
||||
@ -778,7 +778,7 @@ end
|
||||
|
||||
@recipe function f(::Type{Val{:stephist}}, x, y, z)
|
||||
h = _make_hist(
|
||||
tuple(plotattributes[:orientation] == :horizontal ? y : x),
|
||||
tuple(y),
|
||||
plotattributes[:bins],
|
||||
normed = plotattributes[:normalize],
|
||||
weights = plotattributes[:weights],
|
||||
@ -792,7 +792,7 @@ end
|
||||
|
||||
@recipe function f(::Type{Val{:scatterhist}}, x, y, z)
|
||||
h = _make_hist(
|
||||
tuple(plotattributes[:orientation] == :horizontal ? y : x),
|
||||
tuple(y),
|
||||
plotattributes[:bins],
|
||||
normed = plotattributes[:normalize],
|
||||
weights = plotattributes[:weights],
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using Plots, Test
|
||||
|
||||
@testset "axis letter" begin
|
||||
using Plots, RecipesBase
|
||||
@ -21,4 +22,4 @@
|
||||
@testset "$f" for f in [vline, vspan]
|
||||
@test f(data).subplots[1].attr[:title] == "x"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -302,11 +302,6 @@ end
|
||||
lines = readlines(io)
|
||||
@test count(s -> occursin("node", s), lines) == 9
|
||||
end
|
||||
# test .tikz extension
|
||||
file_path =joinpath(path,"annotations.tikz")
|
||||
@test_nowarn savefig(annotation_plot, file_path)
|
||||
@test_nowarn open(file_path) do io
|
||||
end
|
||||
end
|
||||
end # testset
|
||||
@testset "Ribbon" begin
|
||||
@ -326,15 +321,6 @@ end
|
||||
@test ribbon_plot.o !== nothing
|
||||
@test ribbon_plot.o.the_plot !== nothing
|
||||
end # testset
|
||||
@testset "Markers and Paths" begin
|
||||
pl = plot(5 .- ones(9), markershape = [:utriangle, :rect],
|
||||
markersize = 8,
|
||||
color = [:red, :black])
|
||||
Plots._update_plot_object(pl)
|
||||
axis = Plots.pgfx_axes(pl.o)[1]
|
||||
plots = filter(x -> x isa PGFPlotsX.Plot, axis.contents)
|
||||
@test length(plots) == 9
|
||||
end # testset
|
||||
end # testset
|
||||
|
||||
@testset "Extra kwargs" begin
|
||||
@ -355,33 +341,4 @@ end # testset
|
||||
axes = Plots.pgfx_axes(pl.o)
|
||||
@test !haskey(axes[1].options.dict, "axis line shift")
|
||||
@test haskey(axes[2].options.dict, "axis line shift")
|
||||
pl = plot(x->x, -1:1; add = raw"\node at (0,0.5) {\huge hi};", extra_kwargs = :subplot)
|
||||
@test pl[1][:extra_kwargs] == Dict(:add => raw"\node at (0,0.5) {\huge hi};")
|
||||
Plots._update_plot_object(pl)
|
||||
axes = Plots.pgfx_axes(pl.o)
|
||||
@test filter(x->x isa String, axes[1].contents)[1] == raw"\node at (0,0.5) {\huge hi};"
|
||||
plot!(pl)
|
||||
@test pl[1][:extra_kwargs] == Dict(:add => raw"\node at (0,0.5) {\huge hi};")
|
||||
Plots._update_plot_object(pl)
|
||||
axes = Plots.pgfx_axes(pl.o)
|
||||
@test filter(x->x isa String, axes[1].contents)[1] == raw"\node at (0,0.5) {\huge hi};"
|
||||
end # testset
|
||||
|
||||
@testset "Titlefonts" begin
|
||||
pl = plot(1:5, title = "Test me", titlefont = (2, :left))
|
||||
@test pl[1][:title] == "Test me"
|
||||
@test pl[1][:titlefontsize] == 2
|
||||
@test pl[1][:titlefonthalign] == :left
|
||||
Plots._update_plot_object(pl)
|
||||
ax_opt = Plots.pgfx_axes(pl.o)[1].options
|
||||
@test ax_opt["title"] == "Test me"
|
||||
@test(haskey(ax_opt.dict, "title style")) isa Test.Pass
|
||||
pl = plot(1:5, plot_title = "Test me", plot_titlefont = (2, :left))
|
||||
@test pl[:plot_title] == "Test me"
|
||||
@test pl[:plot_titlefontsize] == 2
|
||||
@test pl[:plot_titlefonthalign] == :left
|
||||
pl = heatmap(rand(3,3), colorbar_title = "Test me", colorbar_titlefont = (12, :right))
|
||||
@test pl[1][:colorbar_title] == "Test me"
|
||||
@test pl[1][:colorbar_titlefontsize] == 12
|
||||
@test pl[1][:colorbar_titlefonthalign] == :right
|
||||
end # testset
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user