diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index c714d493..92e515e3 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -88,22 +88,22 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) "horizontal sep" => string(maximum(sp -> sp.minpad[1], plt.subplots)), "vertical sep" => string(maximum(sp -> sp.minpad[2], plt.subplots)), ), - "height" => pl_height > 0 ? string(pl_height)*"px" : "{}", - "width" => pl_width > 0 ? string(pl_width)*"px" : "{}", + "height" => pl_height > 0 ? string(pl_height * px) : "{}", + "width" => pl_width > 0 ? string(pl_width * px) : "{}", ) ) ) end for sp in plt.subplots bb = bbox(sp) + sp_width = width(bb) + sp_height = height(bb) cstr = plot_color(sp[:background_color_legend]) a = alpha(cstr) fg_alpha = alpha(plot_color(sp[:foreground_color_legend])) title_cstr = plot_color(sp[:titlefontcolor]) title_a = alpha(title_cstr) axis_opt = PGFPlotsX.Options( - "height" => string(height(bb)), - "width" => string(width(bb)), "title" => sp[:title], "title style" => PGFPlotsX.Options( "font" => pgfx_font(sp[:titlefontsize], pgfx_thickness_scaling(sp)), @@ -123,6 +123,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) ), "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 if sp[:legend] isa Tuple x, y = sp[:legend] @@ -613,7 +615,6 @@ end function pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index ) ribbon_y = series[:ribbon] - @show ribbon_y opt = series.plotattributes if ribbon_y isa AVec ribbon_n = length(opt[:y]) รท length(ribbon_y) diff --git a/test/test_pgfplotsx.jl b/test/test_pgfplotsx.jl index dfbed5f0..90167f90 100644 --- a/test/test_pgfplotsx.jl +++ b/test/test_pgfplotsx.jl @@ -124,28 +124,39 @@ end u = ones(length(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? + mktempdir() do path + @test_nowarn savefig(arrow_plot, path*"arrow.pdf") + end end # testset @testset "Annotations" begin y = rand(10) 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"))]) - 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 @testset "Ribbon" begin aa = rand(10) bb = rand(10) cc = rand(10) conf = [aa-cc bb-cc] - p = plot(collect(1:10),fill(1,10), ribbon=conf) - Plots._update_plot_object(p) - axis = Plots.pgfx_axes(p.o)[1] + ribbon_plot = plot(collect(1:10),fill(1,10), ribbon=(conf[:,1],conf[:,2])) + Plots._update_plot_object(ribbon_plot) + axis = Plots.pgfx_axes(ribbon_plot.o)[1] plots = filter(x->x isa PGFPlotsX.Plot, axis.contents) @test length(plots) == 4 @test !haskey(plots[1].options.dict, "fill") @test !haskey(plots[2].options.dict, "fill") @test !haskey(plots[3].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