Merge pull request #249 from KristofferC/kc/pgfplots_label
add support for legend and label in pgfplots
This commit is contained in:
commit
dec3748fe5
@ -758,7 +758,7 @@ function convertLegendValue(val::Symbol)
|
|||||||
:best
|
:best
|
||||||
elseif val in (:no, :none)
|
elseif val in (:no, :none)
|
||||||
:none
|
:none
|
||||||
elseif val in (:right, :left, :top, :bottom, :inside, :best, :legend)
|
elseif val in (:right, :left, :top, :bottom, :inside, :best, :legend, :topright, :topleft, :bottomleft, :bottomright)
|
||||||
val
|
val
|
||||||
else
|
else
|
||||||
error("Invalid symbol for legend: $val")
|
error("Invalid symbol for legend: $val")
|
||||||
|
|||||||
@ -10,9 +10,9 @@ supportedArgs(::PGFPlotsBackend) = [
|
|||||||
:fillalpha,
|
:fillalpha,
|
||||||
# :foreground_color,
|
# :foreground_color,
|
||||||
# :group,
|
# :group,
|
||||||
# :label,
|
:label,
|
||||||
# :layout,
|
# :layout,
|
||||||
# :legend,
|
:legend,
|
||||||
:seriescolor, :seriesalpha,
|
:seriescolor, :seriesalpha,
|
||||||
:linecolor,
|
:linecolor,
|
||||||
:linestyle,
|
:linestyle,
|
||||||
@ -99,6 +99,13 @@ const _pgfplots_markers = KW(
|
|||||||
:pentagon => "mark = pentagon*,"
|
:pentagon => "mark = pentagon*,"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const _pgfplots_legend_pos = KW(
|
||||||
|
:bottomleft => "south west",
|
||||||
|
:bottomright => "south east",
|
||||||
|
:topright => "north east",
|
||||||
|
:topleft => "north west"
|
||||||
|
)
|
||||||
|
|
||||||
function _pgfplots_get_color(kwargs, symb)
|
function _pgfplots_get_color(kwargs, symb)
|
||||||
c = typeof(kwargs[symb]) == Symbol ? convertColor(kwargs[symb]) : kwargs[symb].c
|
c = typeof(kwargs[symb]) == Symbol ? convertColor(kwargs[symb]) : kwargs[symb].c
|
||||||
"{rgb,1:red,$(float(c.r));green,$(float(c.g));blue,$(float(c.b))}"
|
"{rgb,1:red,$(float(c.r));green,$(float(c.g));blue,$(float(c.b))}"
|
||||||
@ -153,12 +160,20 @@ function _pgfplots_get_fill_color!(kwargs, plt)
|
|||||||
kwargs[:style] *= "fill opacity = $α,"
|
kwargs[:style] *= "fill opacity = $α,"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _pgfplots_get_label!(kwargs, plt)
|
||||||
|
if plt[:label] != nothing && plt[:legend] != :none
|
||||||
|
kwargs[:legendentry] = plt[:label]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function _pgfplots_get_plot_kwargs(plt)
|
function _pgfplots_get_plot_kwargs(plt)
|
||||||
kwargs = KW()
|
kwargs = KW()
|
||||||
kwargs[:style] = ""
|
kwargs[:style] = ""
|
||||||
_pgfplots_get_linestyle!(kwargs, plt)
|
_pgfplots_get_linestyle!(kwargs, plt)
|
||||||
_pgfplots_get_marker!(kwargs, plt)
|
_pgfplots_get_marker!(kwargs, plt)
|
||||||
_pgfplots_get_series_color!(kwargs, plt)
|
_pgfplots_get_series_color!(kwargs, plt)
|
||||||
|
_pgfplots_get_label!(kwargs, plt)
|
||||||
kwargs
|
kwargs
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -324,6 +339,9 @@ function _pgfplots_get_axis_kwargs(d)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ((d[:legend] != :none) || (d[:legend] != :best)) && (d[:legend] in keys(_pgfplots_legend_pos))
|
||||||
|
axisargs[:legendPos] = _pgfplots_legend_pos[d[:legend]]
|
||||||
|
end
|
||||||
axisargs
|
axisargs
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -331,7 +349,12 @@ end
|
|||||||
|
|
||||||
################# This is the important method to implement!!! #################
|
################# This is the important method to implement!!! #################
|
||||||
function _make_pgf_plot(plt::Plot{PGFPlotsBackend})
|
function _make_pgf_plot(plt::Plot{PGFPlotsBackend})
|
||||||
os = [_pgfplots_axis(plt_series) for plt_series in plt.seriesargs]
|
os = Any[]
|
||||||
|
# We need to send the :legend KW to the axis
|
||||||
|
for plt_series in plt.seriesargs
|
||||||
|
plt_series[:legend] = plt.plotargs[:legend]
|
||||||
|
push!(os, _pgfplots_axis(plt_series))
|
||||||
|
end
|
||||||
axisargs =_pgfplots_get_axis_kwargs(plt.plotargs)
|
axisargs =_pgfplots_get_axis_kwargs(plt.plotargs)
|
||||||
plt.o = PGFPlots.Axis([os...]; axisargs...)
|
plt.o = PGFPlots.Axis([os...]; axisargs...)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1062,7 +1062,11 @@ const _pyplot_legend_pos = KW(
|
|||||||
:right => "right",
|
:right => "right",
|
||||||
:left => "center left",
|
:left => "center left",
|
||||||
:top => "upper center",
|
:top => "upper center",
|
||||||
:bottom => "lower center"
|
:bottom => "lower center",
|
||||||
|
:bottomleft => "lower left",
|
||||||
|
:bottomright => "lower right",
|
||||||
|
:topright => "upper right",
|
||||||
|
:topleft => "upper left"
|
||||||
)
|
)
|
||||||
|
|
||||||
# function addPyPlotLegend(plt::Plot)
|
# function addPyPlotLegend(plt::Plot)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user