diff --git a/src/backends.jl b/src/backends.jl index 04b8d3f01..b18b3c4ad 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -456,6 +456,7 @@ const _gr_attr = merge_with_base_supported([ :titlefontvalign, :titlefontrotation, :titlefontcolor, + :legend_column, :legend_font_family, :legend_font_pointsize, :legend_font_halign, @@ -869,6 +870,7 @@ const _pyplot_attr = merge_with_base_supported([ :titlefontfamily, :titlefontsize, :titlefontcolor, + :legend_column, :legend_font_family, :legend_font_pointsize, :legend_font_color, diff --git a/src/backends/deprecated/pyplot.jl b/src/backends/deprecated/pyplot.jl index 4fc33cfd2..5eb548a88 100644 --- a/src/backends/deprecated/pyplot.jl +++ b/src/backends/deprecated/pyplot.jl @@ -1527,14 +1527,16 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) # if anything was added, call ax.legend and set the colors if !isempty(handles) leg = legend_angle(leg) - ncol = if (lc = sp[:legend_column]) < 0 + ncol = if (lc = sp[:legend_column]) == -1 nseries - elseif lc > 1 - lc == nseries || - @warn "n° of legend_column=$lc is not compatible with n° of series=$nseries" + elseif lc > nseries + @warn "n° of legend_column=$lc is larger than n° of series=$nseries" nseries - else + elseif lc == 0 || lc < -1 + @warn "n° of legend_column=$lc has undefined behaviour. Assuming vertical layout." 1 + else + lc end leg = ax."legend"( handles, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b7ccf0695..2201c360d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1093,9 +1093,12 @@ function gr_add_legend(sp, leg, viewport_area) if vertical ypos -= leg.dy else - # println(string(series[:label]), " ", nentry, " ", nentry % legend_cols) + # row-major sorting xpos += nentry % legend_cols == 0 ? -(legend_cols - 1) * leg.dx : leg.dx ypos -= nentry % legend_cols == 0 ? leg.dy : 0 + # column-major sorting + # xpos += nentry % legend_rows == 0 ? leg.dx : 0 + # ypos -= nentry % legend_rows == 0 ? -(legend_rows - 1) * leg.dy : leg.dy nentry += 1 end end @@ -1222,14 +1225,13 @@ function gr_get_legend_geometry(vp, sp) elseif legend_column > nseries && nseries != 0 # catch plot_title here @warn "n° of legend_column=$legend_column is larger than n° of series=$nseries" (1 + has_title, nseries) - elseif legend_column == 0 - @warn "n° of legend_column=$legend_column. Assuming vertical layout." + elseif legend_column == 0 || legend_column < -1 + @warn "n° of legend_column=$legend_column has undefined behaviour. Assuming vertical layout." vertical = true (has_title + nseries, 1) else (ceil(Int64, nseries / legend_column) + has_title, legend_column) end - #println(column_layout) base_factor = width(vp) / 45 # determines legend box base width (arbitrarily based on `width`) diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index 11e411559..10fa58ea2 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -1426,14 +1426,19 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) isempty(handles) && return leg = legend_angle(leg) - ncol = if (lc = sp[:legend_column]) < 0 + ncol = if (lc = sp[:legend_column]) == -1 nseries - elseif lc > 1 - lc == nseries || - @warn "n° of legend_column=$lc is not compatible with n° of series=$nseries" + elseif lc > nseries + #lc == nseries || + # @warn "n° of legend_column=$lc is not compatible with n° of series=$nseries" + #nseries + @warn "n° of legend_column=$lc is larger than n° of series=$nseries" nseries - else + elseif lc == 0 || lc < -1 + @warn "n° of legend_column=$lc has undefined behaviour. Assuming vertical layout." 1 + else + lc end leg = ax.legend( handles, @@ -1447,7 +1452,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) framealpha = alpha(plot_color(sp[:legend_background_color])), fancybox = false, # makes the legend box square # borderpad = 0.8, # to match GR legendbox - ncol, + ncols = ncol, ) leg.get_frame().set_linewidth(_py_thickness_scale(plt, 1)) leg.set_zorder(1_000)