From 1a91eacdcb784ab778424266db95a9130edc7076 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Fri, 20 Jan 2017 15:26:54 +0100 Subject: [PATCH 1/9] Enable histogram plotting in pgfplot --- src/backends/pgfplots.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index b42e8629..a1548b5e 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -32,7 +32,7 @@ const _pgfplots_attr = merge_with_base_supported([ :aspect_ratio, # :match_dimensions, ]) -const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour] +const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon] #vcat(_allMarkers, Shape) const _pgfplots_scale = [:identity, :ln, :log2, :log10] @@ -147,7 +147,7 @@ function pgf_series(sp::Subplot, series::Series) push!(style, pgf_linestyle(d)) push!(style, pgf_marker(d)) - if d[:fillrange] != nothing + if d[:fillcolor] != nothing push!(style, pgf_fillstyle(d)) end From bcd5d9ef9087cbf9577ce5ff4710b5e56f750045 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Sun, 22 Jan 2017 16:57:28 +0100 Subject: [PATCH 2/9] Fix issue where every series is plotted with a fillcolor --- src/backends/pgfplots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index a1548b5e..754ebaa0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -147,7 +147,7 @@ function pgf_series(sp::Subplot, series::Series) push!(style, pgf_linestyle(d)) push!(style, pgf_marker(d)) - if d[:fillcolor] != nothing + if d[:fillrange] != nothing || st in (:shape,) push!(style, pgf_fillstyle(d)) end From caf86686ddf8e7c190ffbf8ed8ae011fce89d3dd Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Mon, 23 Jan 2017 13:56:40 +0100 Subject: [PATCH 3/9] Fix yshift of subplots. Calculation of coordinate transformation from bb to pgf did not consider the height of the plot. --- src/backends/pgfplots.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 754ebaa0..9ecc0ae4 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -249,8 +249,12 @@ end function _update_plot_object(plt::Plot{PGFPlotsBackend}) plt.o = PGFPlots.Axis[] + # Obtain the total height of the plot by extracting the maximal bottom + # coordinate from the bounding box. + # TODO: Maybe there is a better way to get the total height of the plot. + total_height = maximum([bottom(bbox(sp)) for sp in plt.subplots]) for sp in plt.subplots - # first build the PGFPlots.Axis object + # first build the PGFPlots.Axis object style = ["unbounded coords=jump"] kw = KW() @@ -268,7 +272,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) bb = bbox(sp) push!(style, """ xshift = $(left(bb).value)mm, - yshift = $((height(bb) - (bottom(bb))).value)mm, + yshift = $((total_height - (bottom(bb))).value)mm, axis background/.style={fill=$(pgf_color(sp[:background_color_inside])[1])} """) kw[:width] = "$(width(bb).value)mm" From f8b84185acb747cb827aed29ca59bf39825b2e33 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Mon, 23 Jan 2017 14:28:26 +0100 Subject: [PATCH 4/9] Add rounding and obtain plot height from layout bbox --- src/backends/pgfplots.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 9ecc0ae4..4feb46d0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -251,8 +251,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) plt.o = PGFPlots.Axis[] # Obtain the total height of the plot by extracting the maximal bottom # coordinate from the bounding box. - # TODO: Maybe there is a better way to get the total height of the plot. - total_height = maximum([bottom(bbox(sp)) for sp in plt.subplots]) + total_height = bottom(bbox(plt.layout)) for sp in plt.subplots # first build the PGFPlots.Axis object style = ["unbounded coords=jump"] @@ -269,10 +268,12 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # bounding box values are in mm # note: bb origin is top-left, pgf is bottom-left + # A round on 2 decimal places should be enough precision for 300 dpi + # plots. bb = bbox(sp) push!(style, """ xshift = $(left(bb).value)mm, - yshift = $((total_height - (bottom(bb))).value)mm, + yshift = $(round((total_height - (bottom(bb))).value,2))mm, axis background/.style={fill=$(pgf_color(sp[:background_color_inside])[1])} """) kw[:width] = "$(width(bb).value)mm" From d5eafad48ed0fff9b52fdad044f9bbfac7b5f370 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Thu, 2 Feb 2017 16:05:17 +0100 Subject: [PATCH 5/9] Add annotations and series_annotations to pgfplots --- src/backends/pgfplots.jl | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 4feb46d0..6d8be4ba 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -3,7 +3,7 @@ # significant contributions by: @pkofod const _pgfplots_attr = merge_with_base_supported([ - # :annotations, + :annotations, # :background_color_legend, :background_color_inside, # :background_color_outside, @@ -27,7 +27,7 @@ const _pgfplots_attr = merge_with_base_supported([ # :ribbon, :quiver, :arrow, # :orientation, # :overwrite_figure, - # :polar, + :polar, # :normalize, :weights, :contours, :aspect_ratio, # :match_dimensions, @@ -136,6 +136,20 @@ function pgf_marker(d::KW) }""" end +function pgf_add_annotation!(o,x,y,val) + # Construct the style string. + # Currently supports color and orientation + halign = val.font.halign == :hcenter ? "" : string(val.font.halign) + cstr,a = pgf_color(val.font.color) + push!(o, PGFPlots.Plots.Node(val.str, # Annotation Text + x, y, # x,y + style=""" + $halign, + color=$cstr, draw opacity=$(convert(Float16,a)), + rotate=$(val.font.rotation) + """)) +end + # -------------------------------------------------------------------------------------- function pgf_series(sp::Subplot, series::Series) @@ -298,14 +312,25 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # add the series object to the PGFPlots.Axis for series in series_list(sp) push!(o, pgf_series(sp, series)) + + # add series annotations + anns = series[:series_annotations] + for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y]) + pgf_add_annotation!(o, xi, yi, PlotText(str, fnt)) + end end + # add the annotations + for ann in sp[:annotations] + pgf_add_annotation!(o,ann...) + end + + # add the PGFPlots.Axis to the list push!(plt.o, o) end end - function _show(io::IO, mime::MIME"image/svg+xml", plt::Plot{PGFPlotsBackend}) show(io, mime, plt.o) end From 48ff2fb8b80bd2477c0a6335d7909a725eb8ccea Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Thu, 2 Feb 2017 16:06:59 +0100 Subject: [PATCH 6/9] Merge branch 'master' of https://github.com/JuliaPlots/Plots.jl --- src/backends/inspectdr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index af95c76a..4f6a57f9 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -454,9 +454,9 @@ function _update_min_padding!(sp::Subplot{InspectDRBackend}) # add in the user-specified margin to InspectDR padding: leftpad = abs(bb.xmin)*px + sp[:left_margin] - toppad = abs(bb.ymax)*px + sp[:top_margin] + toppad = abs(bb.ymin)*px + sp[:top_margin] rightpad = abs(bb.xmax)*px + sp[:right_margin] - bottompad = abs(bb.ymin)*px + sp[:bottom_margin] + bottompad = abs(bb.ymax)*px + sp[:bottom_margin] sp.minpad = (leftpad, toppad, rightpad, bottompad) end From dd505fedccf89204c6a99021d4a7006fb4821c43 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Thu, 2 Feb 2017 16:43:30 +0100 Subject: [PATCH 7/9] Add support for polar axis --- src/backends/pgfplots.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 6d8be4ba..c9bd9fba 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -307,7 +307,11 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:legendPos] = _pgfplots_legend_pos[legpos] end - o = PGFPlots.Axis(; style = style, kw...) + axisf = PGFPlots.Axis + if sp[:projection] == :polar + axisf = PGFPlots.PolarAxis + end + o = axisf(; style = style, kw...) # add the series object to the PGFPlots.Axis for series in series_list(sp) From 1111000217396f9bae5dd2c3db4e3b95156c73b0 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Thu, 2 Feb 2017 17:39:34 +0100 Subject: [PATCH 8/9] Add support for ticks rotation --- src/backends/pgfplots.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index c9bd9fba..c45f9157 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -225,6 +225,9 @@ function pgf_axis(sp::Subplot, letter) # axis guide kw[Symbol(letter,:label)] = axis[:guide] + # ticks + push!(style, "$(letter)ticklabel style={rotate = $(axis[:rotation])}") + # flip/reverse? axis[:flip] && push!(style, "$letter dir=reverse") From d883274586c0774d51c5c64d50600e6faaeb9540 Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Fri, 3 Feb 2017 08:25:55 +0100 Subject: [PATCH 9/9] Fix comments --- src/backends/pgfplots.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index c45f9157..de4d4a6a 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -142,7 +142,7 @@ function pgf_add_annotation!(o,x,y,val) halign = val.font.halign == :hcenter ? "" : string(val.font.halign) cstr,a = pgf_color(val.font.color) push!(o, PGFPlots.Plots.Node(val.str, # Annotation Text - x, y, # x,y + x, y, style=""" $halign, color=$cstr, draw opacity=$(convert(Float16,a)), @@ -225,7 +225,7 @@ function pgf_axis(sp::Subplot, letter) # axis guide kw[Symbol(letter,:label)] = axis[:guide] - # ticks + # Add ticklabel rotations push!(style, "$(letter)ticklabel style={rotate = $(axis[:rotation])}") # flip/reverse?