fix dimensions

This commit is contained in:
Simon Christ 2019-12-06 19:37:35 +01:00
parent 9534bae4ef
commit d2c0840c43
2 changed files with 22 additions and 10 deletions

View File

@ -88,22 +88,22 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
"horizontal sep" => string(maximum(sp -> sp.minpad[1], plt.subplots)), "horizontal sep" => string(maximum(sp -> sp.minpad[1], plt.subplots)),
"vertical sep" => string(maximum(sp -> sp.minpad[2], plt.subplots)), "vertical sep" => string(maximum(sp -> sp.minpad[2], plt.subplots)),
), ),
"height" => pl_height > 0 ? string(pl_height)*"px" : "{}", "height" => pl_height > 0 ? string(pl_height * px) : "{}",
"width" => pl_width > 0 ? string(pl_width)*"px" : "{}", "width" => pl_width > 0 ? string(pl_width * px) : "{}",
) )
) )
) )
end end
for sp in plt.subplots for sp in plt.subplots
bb = bbox(sp) bb = bbox(sp)
sp_width = width(bb)
sp_height = height(bb)
cstr = plot_color(sp[:background_color_legend]) cstr = plot_color(sp[:background_color_legend])
a = alpha(cstr) a = alpha(cstr)
fg_alpha = alpha(plot_color(sp[:foreground_color_legend])) fg_alpha = alpha(plot_color(sp[:foreground_color_legend]))
title_cstr = plot_color(sp[:titlefontcolor]) title_cstr = plot_color(sp[:titlefontcolor])
title_a = alpha(title_cstr) title_a = alpha(title_cstr)
axis_opt = PGFPlotsX.Options( axis_opt = PGFPlotsX.Options(
"height" => string(height(bb)),
"width" => string(width(bb)),
"title" => sp[:title], "title" => sp[:title],
"title style" => PGFPlotsX.Options( "title style" => PGFPlotsX.Options(
"font" => pgfx_font(sp[:titlefontsize], pgfx_thickness_scaling(sp)), "font" => pgfx_font(sp[:titlefontsize], pgfx_thickness_scaling(sp)),
@ -123,6 +123,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
), ),
"axis on top" => nothing, "axis on top" => nothing,
) )
sp_width > 0*mm ? push!(axis_opt, "width" => string(sp_width)) : nothing
sp_height > 0*mm ? push!(axis_opt, "height" => string(sp_height)) : nothing
# legend position # legend position
if sp[:legend] isa Tuple if sp[:legend] isa Tuple
x, y = sp[:legend] x, y = sp[:legend]
@ -613,7 +615,6 @@ end
function pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index ) function pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index )
ribbon_y = series[:ribbon] ribbon_y = series[:ribbon]
@show ribbon_y
opt = series.plotattributes opt = series.plotattributes
if ribbon_y isa AVec if ribbon_y isa AVec
ribbon_n = length(opt[:y]) ÷ length(ribbon_y) ribbon_n = length(opt[:y]) ÷ length(ribbon_y)

View File

@ -124,28 +124,39 @@ end
u = ones(length(x)) u = ones(length(x))
v = cos.(x) v = cos.(x)
plot( x, y, quiver = (u, v), arrow = true ) arrow_plot = plot( x, y, quiver = (u, v), arrow = true )
# TODO: could adjust limits to fit arrows if too long, but how? # TODO: could adjust limits to fit arrows if too long, but how?
mktempdir() do path
@test_nowarn savefig(arrow_plot, path*"arrow.pdf")
end
end # testset end # testset
@testset "Annotations" begin @testset "Annotations" begin
y = rand(10) y = rand(10)
plot(y, annotations=(3, y[3], Plots.text("this is \\#3", :left)), leg=false) plot(y, annotations=(3, y[3], Plots.text("this is \\#3", :left)), leg=false)
annotate!([(5, y[5], Plots.text("this is \\#5", 16, :red, :center)), (10, y[10], Plots.text("this is \\#10", :right, 20, "courier"))]) annotate!([(5, y[5], Plots.text("this is \\#5", 16, :red, :center)), (10, y[10], Plots.text("this is \\#10", :right, 20, "courier"))])
scatter!(range(2, stop=8, length=6), rand(6), marker=(50, 0.2, :orange), series_annotations=["series", "annotations", "map", "to", "series", Plots.text("data", :green)]) annotation_plot = scatter!(range(2, stop=8, length=6), rand(6), marker=(50, 0.2, :orange), series_annotations=["series", "annotations", "map", "to", "series", Plots.text("data", :green)])
mktempdir() do path
@test_nowarn savefig(annotation_plot, path*"annotation.pdf")
end
end # testset end # testset
@testset "Ribbon" begin @testset "Ribbon" begin
aa = rand(10) aa = rand(10)
bb = rand(10) bb = rand(10)
cc = rand(10) cc = rand(10)
conf = [aa-cc bb-cc] conf = [aa-cc bb-cc]
p = plot(collect(1:10),fill(1,10), ribbon=conf) ribbon_plot = plot(collect(1:10),fill(1,10), ribbon=(conf[:,1],conf[:,2]))
Plots._update_plot_object(p) Plots._update_plot_object(ribbon_plot)
axis = Plots.pgfx_axes(p.o)[1] axis = Plots.pgfx_axes(ribbon_plot.o)[1]
plots = filter(x->x isa PGFPlotsX.Plot, axis.contents) plots = filter(x->x isa PGFPlotsX.Plot, axis.contents)
@test length(plots) == 4 @test length(plots) == 4
@test !haskey(plots[1].options.dict, "fill") @test !haskey(plots[1].options.dict, "fill")
@test !haskey(plots[2].options.dict, "fill") @test !haskey(plots[2].options.dict, "fill")
@test !haskey(plots[3].options.dict, "fill") @test !haskey(plots[3].options.dict, "fill")
@test haskey(plots[4].options.dict, "fill") @test haskey(plots[4].options.dict, "fill")
@test ribbon_plot.o !== nothing
@test ribbon_plot.o.the_plot !== nothing
mktempdir() do path
@test_nowarn savefig(ribbon_plot, path*"ribbon.svg")
end
end # testset end # testset
end # testset end # testset