From 9e74976d6d97c0f7731fec2e3bf17ff8a54ddea9 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 13 Nov 2019 16:00:50 +0100 Subject: [PATCH] axes labels, legend entries, line color, marker shapes --- src/backends/pgfplotsx.jl | 60 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index a62f2317..44ac5994 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1,4 +1,38 @@ using PGFPlotsX: PGFPlotsX + +const _pgfplotsx_linestyles = KW( + :solid => "solid", + :dash => "dashed", + :dot => "dotted", + :dashdot => "dashdotted", + :dashdotdot => "dashdotdotted", +) + +const _pgfplotsx_markers = KW( + :none => "none", + :cross => "+", + :xcross => "x", + :+ => "+", + :x => "x", + :utriangle => "triangle*", + :dtriangle => "triangle*", + :circle => "*", + :rect => "square*", + :star5 => "star", + :star6 => "asterisk", + :diamond => "diamond*", + :pentagon => "pentagon*", + :hline => "-", + :vline => "|" +) + +const _pgfplotsx_legend_pos = KW( + :bottomleft => "south west", + :bottomright => "south east", + :topright => "north east", + :topleft => "north west", + :outertopright => "outer north east", +) # -------------------------------------------------------------------------------------- # display calls this and then _display, its called 3 times for plot(1:5) function _update_plot_object(plt::Plot{PGFPlotsXBackend}) @@ -6,10 +40,32 @@ function _update_plot_object(plt::Plot{PGFPlotsXBackend}) local axis for sp in plt.subplots - axis = PGFPlotsX.Axis() + bb = bbox(sp) + axis = PGFPlotsX.@pgf PGFPlotsX.Axis( + { + xlabel = sp.attr[:xaxis][:guide], + ylabel = sp.attr[:yaxis][:guide], + height = string(height(bb)), + width = string(width(bb)), + title = sp[:title], + }, + ) for series in series_list(sp) - series_plot = PGFPlotsX.Plot(PGFPlotsX.Coordinates(series[:x],series[:y])) + opt = series.plotattributes + series_plot = PGFPlotsX.@pgf PGFPlotsX.Plot( + { + color = opt[:linecolor], + mark = _pgfplotsx_markers[opt[:markershape]], + # TODO: how to do nested options? + # "mark options" = "{color = $(opt[:markercolor])}", + }, + PGFPlotsX.Coordinates(series[:x],series[:y]) + ) push!( axis, series_plot ) + if opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) + push!( axis, PGFPlotsX.LegendEntry( opt[:label] ) + ) + end end end push!( plt.o, axis )