Compare commits

..
25 Commits
Author SHA1 Message Date
Simon ChristandGitHub fa720d6ad4 patch release [skip ci] 2020-07-09 12:32:04 +02:00
Simon ChristandGitHub 1ab681f509 fix ribbons (#2853)
* fix ribbons

* fix tests
2020-07-09 12:23:27 +02:00
Daniel SchwabenederandGitHub 0d776fd09d Merge pull request #2850 from daschw/gr-error
fix yerror and marker_z
2020-07-08 08:58:12 +02:00
Daniel Schwabeneder 45e33f5b6f fix yerror and marker_z 2020-07-07 21:44:47 +02:00
Daniel SchwabenederandGitHub 1c4910f90e Merge pull request #2807 from MLH-Fellowship/diaga-issue-2202-2330
Fix #2330, #2202: Position legends closer to the borders
2020-07-07 20:55:00 +02:00
Simon ChristandGitHub 2f4eb7b558 change z buffer for surface plots (#2843) 2020-07-04 19:37:42 +02:00
Daniel SchwabenederandGitHub 07ed5e7162 Merge pull request #2846 from daschw/release
patch release
2020-07-04 12:17:23 +02:00
Daniel Schwabeneder 03716289c3 patch release [skip ci] 2020-07-04 12:16:13 +02:00
Daniel SchwabenederandGitHub 0d38f34e54 Merge pull request #2844 from daschw/errorbar
fix errorbar color
2020-07-03 17:09:17 +02:00
Daniel Schwabeneder 2544808000 update errorbar example 2020-07-03 16:31:03 +02:00
Diaga 02ca049bc6 Remove static offsets for ypos 2020-07-03 18:52:54 +05:00
Daniel Schwabeneder cd20518323 fix errorbar color for scatter 2020-07-03 15:40:46 +02:00
Diaga ff7235e9b8 Remove constant offsets for xpos 2020-07-03 17:56:13 +05:00
Daniel SchwabenederandGitHub fb5307ace6 Merge pull request #2840 from daschw/release
patch release
2020-07-02 16:42:47 +02:00
e3512b0f0d Add label for label=0 kwarg (#2837)
* Add label for `label=0` kwarg

* Fix ambiguous comparision of label with 0

* Add methods for handling plot labels

* Remove type annotations for series indexes

* Replace label conversion code with shorter version

* Handel symbol args for labels in more consistent manner

* Broadcast label_to_string to handle Array of labels

Co-authored-by: Simon Christ <SimonChrist@gmx.de>

Co-authored-by: Simon Christ <SimonChrist@gmx.de>
2020-07-02 16:32:37 +02:00
Diaga 376fae0d79 Make legend offset calculation dynamic 2020-07-02 18:12:23 +05:00
Daniel Schwabeneder e0e240bfd2 bump version [skip ci] 2020-07-02 14:41:04 +02:00
Daniel SchwabenederandGitHub 079152a69a Merge pull request #2839 from daschw/precompile
include precompile_includer.jl
2020-07-02 14:39:20 +02:00
Daniel Schwabeneder ffed7ebc21 undo version change in SnoopCompile.jl 2020-07-02 13:55:10 +02:00
Daniel Schwabeneder cc7c0f1251 change julia 1.5.0 version 2020-07-02 13:51:57 +02:00
Daniel Schwabeneder 30c683b201 include prercompile_includer.jl manually 2020-07-02 13:50:26 +02:00
Daniel SchwabenederandGitHub c3fa7c8941 Merge pull request #2836 from daschw/windows-tests
Make tests pass on windows julia 1.3
2020-07-01 12:07:20 +02:00
Daniel Schwabeneder ddc89e54f1 fix undefined is_ci 2020-07-01 10:32:04 +02:00
Daniel Schwabeneder 0a929d6022 try to fix tests on windows julia 1.3 2020-07-01 09:44:27 +02:00
Diaga d036794576 Fix #2330, #2202: Position legends closer to the borders 2020-06-22 17:45:23 +05:00
11 changed files with 126 additions and 83 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
name: Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.version == 'nightly' || (matrix.version == '1.3' && matrix.os == 'windows-latest')}}
continue-on-error: ${{ matrix.version == 'nightly' }}
strategy:
fail-fast: false
matrix:
+1 -1
View File
@@ -1,7 +1,7 @@
name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"]
version = "1.5.1"
version = "1.5.4"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
+2
View File
@@ -250,4 +250,6 @@ end
const CURRENT_BACKEND = CurrentBackend(:none)
include("precompile_includer.jl")
end # module
+24 -13
View File
@@ -20,14 +20,14 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol})
end
end
function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol})
for arg in args
s = string(arg)
if '_' in s
aliases[Symbol(replace(s, "_" => ""))] = arg
end
end
end
function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol})
for arg in args
s = string(arg)
if '_' in s
aliases[Symbol(replace(s, "_" => ""))] = arg
end
end
end
# ------------------------------------------------------------
const _allAxes = [:auto, :left, :right]
@@ -235,7 +235,7 @@ const _bar_width = 0.8
# -----------------------------------------------------------------------------
const _series_defaults = KW(
:label => "AUTO",
:label => :auto,
:colorbar_entry => true,
:seriescolor => :auto,
:seriesalpha => nothing,
@@ -1569,6 +1569,20 @@ function _slice_series_args!(plotattributes::AKW, plt::Plot, sp::Subplot, comman
return plotattributes
end
label_to_string(label::Bool, series_plotindex) = label ? label_to_string(:auto, series_plotindex) : ""
label_to_string(label::Nothing, series_plotindex) = ""
label_to_string(label::Missing, series_plotindex) = ""
function label_to_string(label::Symbol, series_plotindex)
if label==:auto
return string("y", series_plotindex)
elseif label==:none
return ""
else
throw(ArgumentError("unsupported symbol $(label) passed to `label`"))
end
end
label_to_string(label, series_plotindex) = string(label) # Fallback to string promotion
function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot)
pkg = plt.backend
globalIndex = plotattributes[:series_plotindex]
@@ -1637,10 +1651,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot)
end
# set label
label = plotattributes[:label]
label = (label == "AUTO" ? "y$globalIndex" : label)
label = label in (:none, nothing, false) ? "" : label
plotattributes[:label] = label
plotattributes[:label] = label_to_string.(plotattributes[:label], globalIndex)
_replace_linewidth(plotattributes)
plotattributes
+32 -21
View File
@@ -349,11 +349,13 @@ function gr_draw_markers(
shapes = series[:markershape]
if shapes != :none
for i in eachindex(x)
for (i, rng) in enumerate(iter_segments(series))
ms = get_thickness_scaling(series) * _cycle(msize, i)
msw = get_thickness_scaling(series) * _cycle(strokewidth, i)
shape = _cycle(shapes, i)
gr_draw_marker(series, x[i], y[i], clims, i, ms, msw, shape)
for j in rng
gr_draw_marker(series, _cycle(x, j), _cycle(y, j), clims, i, ms, msw, shape)
end
end
end
end
@@ -565,6 +567,8 @@ gr_view_xcenter(viewport_plotarea) = 0.5 * (viewport_plotarea[1] + viewport_plot
gr_view_ycenter(viewport_plotarea) = 0.5 * (viewport_plotarea[3] + viewport_plotarea[4])
function gr_legend_pos(sp::Subplot, w, h, viewport_plotarea)
legend_leftw, legend_rightw, legend_textw, x_legend_offset = w
legend_dy, legendh, y_legend_offset = h
s = sp[:legend]
typeof(s) <: Symbol || return gr_legend_pos(s, w, h, viewport_plotarea)
str = string(s)
@@ -579,34 +583,34 @@ function gr_legend_pos(sp::Subplot, w, h, viewport_plotarea)
if occursin("right", str)
if occursin("outer", str)
# As per https://github.com/jheinen/GR.jl/blob/master/src/jlgr.jl#L525
xpos = viewport_plotarea[2] + 0.11 + ymirror * gr_axis_width(sp, sp[:yaxis])
xpos = viewport_plotarea[2] + x_legend_offset + legend_leftw + ymirror * gr_axis_width(sp, sp[:yaxis])
else
xpos = viewport_plotarea[2] - 0.05 - w
xpos = viewport_plotarea[2] - legend_rightw - legend_textw
end
elseif occursin("left", str)
if occursin("outer", str)
xpos = viewport_plotarea[1] - 0.05 - w - !ymirror * gr_axis_width(sp, sp[:yaxis])
xpos = viewport_plotarea[1] - !ymirror * gr_axis_width(sp, sp[:yaxis]) - x_legend_offset * 2 - legend_rightw - legend_textw
else
xpos = viewport_plotarea[1] + 0.11
xpos = viewport_plotarea[1] + legend_leftw + x_legend_offset
end
else
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04 + viewport_plotarea[1]
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 + viewport_plotarea[1] + legend_leftw - legend_rightw - legend_textw - x_legend_offset * 2
end
if occursin("top", str)
if s == :outertop
ypos = viewport_plotarea[4] + 0.02 + h + xmirror * gr_axis_height(sp, sp[:xaxis])
ypos = viewport_plotarea[4] + y_legend_offset + legendh + xmirror * gr_axis_height(sp, sp[:xaxis])
else
ypos = viewport_plotarea[4] - 0.06
ypos = viewport_plotarea[4] - y_legend_offset
end
elseif occursin("bottom", str)
if s == :outerbottom
ypos = viewport_plotarea[3] - 0.05 - !xmirror * gr_axis_height(sp, sp[:xaxis])
ypos = viewport_plotarea[3] - y_legend_offset - legendh - !xmirror * gr_axis_height(sp, sp[:xaxis])
else
ypos = viewport_plotarea[3] + h + 0.06
ypos = viewport_plotarea[3] + legendh + y_legend_offset
end
else
# Adding min y to shift legend pos to correct graph (#2377)
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2 + viewport_plotarea[3]
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + legendh/2 + viewport_plotarea[3]
end
(xpos,ypos)
end
@@ -1003,26 +1007,33 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
legendn += 1
lab = series[:label]
tbx, tby = gr_inqtext(0, 0, string(lab))
legendw = max(legendw, tbx[3] - tbx[1])
legendw = max(legendw, tbx[3] - tbx[1]) # Holds text width right now
end
GR.setscale(1)
GR.selntran(1)
GR.restorestate()
end
legend_textw = legendw
legend_rightw = 0.02 # To be made dynamic in a follow up PR
legend_leftw = 0.08 # To be made dynamic in a follow up PR
total_legendw = legend_textw + legend_leftw + legend_rightw
x_legend_offset = (viewport_plotarea[2] - viewport_plotarea[1]) / 30
y_legend_offset = (viewport_plotarea[4] - viewport_plotarea[3]) / 30
dy = gr_point_mult(sp) * sp[:legendfontsize] * 1.75
legendh = dy * legendn
leg_str = string(sp[:legend])
if occursin("outer", leg_str)
if occursin("right", leg_str)
viewport_plotarea[2] -= legendw + 0.12
viewport_plotarea[2] -= total_legendw + x_legend_offset # Lessen plot max width to make space for outer legend
elseif occursin("left", leg_str)
viewport_plotarea[1] += legendw + 0.11
viewport_plotarea[1] += total_legendw + x_legend_offset # Increase plot min width to make space for outer legend
elseif occursin("top", leg_str)
viewport_plotarea[4] -= legendh + 0.03
viewport_plotarea[4] -= legendh + dy + y_legend_offset
elseif occursin("bottom", leg_str)
viewport_plotarea[3] += legendh + 0.04
viewport_plotarea[3] += legendh + dy + y_legend_offset
end
end
if sp[:legend] == :inline
@@ -1840,17 +1851,17 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.selntran(0)
GR.setscale(0)
gr_set_font(legendfont(sp), sp)
w = legendw
w = legendw # This is the legend text width
n = legendn
if w > 0
dy = gr_point_mult(sp) * sp[:legendfontsize] * 1.75
h = dy*n
xpos, ypos = gr_legend_pos(sp, w, h, viewport_plotarea)
xpos, ypos = gr_legend_pos(sp, [legend_leftw, legend_rightw, legend_textw, x_legend_offset, y_legend_offset], [dy, h, y_legend_offset], viewport_plotarea) # Passing legend width components instead of legend text width
GR.setfillintstyle(GR.INTSTYLE_SOLID)
gr_set_fillcolor(sp[:background_color_legend])
GR.fillrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n)
GR.fillrect(xpos - legend_leftw, xpos + legend_textw + legend_rightw, ypos + dy, ypos - dy * n) # Allocating white space for actual legend width here
gr_set_line(1, :solid, sp[:foreground_color_legend], sp)
GR.drawrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n)
GR.drawrect(xpos - legend_leftw, xpos + legend_textw + legend_rightw, ypos + dy, ypos - dy * n) # Drawing actual legend width here
i = 0
if sp[:legendtitle] !== nothing
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
+14 -17
View File
@@ -344,9 +344,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end
# add fillrange
if sf !== nothing &&
!isfilledcontour(series) &&
series[:ribbon] === nothing
if sf isa Number || sf isa AVec
!isfilledcontour(series)
if sf isa Number || sf isa AVec
pgfx_fillrange_series!(
axis,
series,
@@ -355,6 +354,17 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
_cycle(sf, rng),
rng,
)
elseif sf isa Tuple
for sfi in sf
pgfx_fillrange_series!(
axis,
series,
series_func,
i,
_cycle(sfi, rng),
rng,
)
end
end
if i == 1 &&
sp[:legend] != :none && pgfx_should_add_to_legend(series)
@@ -384,17 +394,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
),
)
end
# add ribbons?
ribbon = series[:ribbon]
if ribbon !== nothing
pgfx_add_ribbons!(
axis,
series,
segment_plot,
series_func,
series_index,
)
end
# add to legend?
if sp[:legend] != :none
leg_entry = if opt[:label] isa AVec
@@ -412,9 +411,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
push!(axis.contents[end].options, "forget plot" => nothing)
else
leg_opt = PGFPlotsX.Options()
if ribbon !== nothing
pgfx_filllegend!(axis.contents[end - 3].options, opt)
end
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
push!(axis, legend)
end
@@ -558,6 +554,7 @@ function pgfx_series_coordinates!(st_val::Val{:surface}, segment_opt, opt, args)
"surf" => nothing,
"mesh/rows" => length(opt[:x]),
"mesh/cols" => length(opt[:y]),
"z buffer" => "sort",
)
return PGFPlotsX.Coordinates(args...)
end
+2 -2
View File
@@ -973,8 +973,8 @@ const _examples = PlotExample[
surf = Measurement.((1:10) .* (1:10)', rand(10,10))
plot(
scatter(x, [x y], msw = 0),
scatter(x, y, z, msw = 0),
scatter(x, [x y]),
scatter(x, y, z),
heatmap(x, y, surf),
wireframe(x, y, surf),
legend = :topleft
+17 -1
View File
@@ -1027,8 +1027,24 @@ end
# Error Bars
function error_style!(plotattributes::AKW)
msc = plotattributes[:markerstrokecolor]
msc = if msc === :match
plotattributes[:subplot][:foreground_color_subplot]
elseif msc === :auto
get_series_color(
plotattributes[:linecolor],
plotattributes[:subplot],
plotattributes[:series_plotindex],
plotattributes[:seriestype],
)
else
msc
end
plotattributes[:seriestype] = :path
plotattributes[:markercolor] = plotattributes[:markerstrokecolor]
plotattributes[:markerstrokecolor] = msc
plotattributes[:markercolor] = msc
plotattributes[:linecolor] = msc
plotattributes[:linewidth] = plotattributes[:markerstrokewidth]
plotattributes[:label] = ""
end
+24 -14
View File
@@ -16,14 +16,21 @@ function fix_rand!(ex)
pushfirst!(ex.args[1].args, :(rng = StableRNG(1234)))
end
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !is_ci(), sigma = [1,1], tol = 1e-2)
function image_comparison_tests(
pkg::Symbol,
idx::Int;
debug = false,
popup = !is_ci(),
sigma = [1, 1],
tol = 1e-2,
)
Plots._debugMode.on = debug
example = Plots._examples[idx]
Plots.theme(:default)
@info("Testing plot: $pkg:$idx:$(example.header)")
backend(pkg)
backend()
default(size=(500,300))
default(size = (500, 300))
fn = "ref$idx.png"
reffn = reference_file(pkg, idx, _current_plots_version)
@@ -40,19 +47,22 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !i
# the test
vtest = VisualTest(func, reffn, idx)
test_images(vtest, popup=popup, sigma=sigma, tol=tol, newfn = newfn)
test_images(vtest, popup = popup, sigma = sigma, tol = tol, newfn = newfn)
end
function image_comparison_facts(pkg::Symbol;
skip = [], # skip these examples (int index)
only = nothing, # limit to these examples (int index)
debug = false, # print debug information?
sigma = [1,1], # number of pixels to "blur"
tol = 1e-2) # acceptable error (percent)
for i in 1:length(Plots._examples)
i in skip && continue
if only === nothing || i in only
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, tol=tol) |> success == true
function image_comparison_facts(
pkg::Symbol;
skip = [], # skip these examples (int index)
only = nothing, # limit to these examples (int index)
debug = false, # print debug information?
sigma = [1, 1], # number of pixels to "blur"
tol = 1e-2,
) # acceptable error (percent)
for i = 1:length(Plots._examples)
i in skip && continue
if only === nothing || i in only
@test image_comparison_tests(pkg, i, debug = debug, sigma = sigma, tol = tol) |>
success == true
end
end
end
end
+6 -6
View File
@@ -45,27 +45,27 @@ include("imgcomp.jl")
Random.seed!(1234)
default(show=false, reuse=true)
is_ci() = get(ENV, "CI", "false") == "true"
img_tol = is_ci() ? 1e-2 : Sys.islinux() ? 1e-3 : 0.1
const IMG_TOL = VERSION < v"1.4" && Sys.iswindows() ? 1e-1 : is_ci() ? 1e-2 : 1e-3
## Uncomment the following lines to update reference images for different backends
# @testset "GR" begin
# image_comparison_facts(:gr, tol=img_tol, skip = Plots._backend_skips[:gr])
# image_comparison_facts(:gr, tol=IMG_TOL, skip = Plots._backend_skips[:gr])
# end
#
# plotly()
# @testset "Plotly" begin
# image_comparison_facts(:plotly, tol=img_tol, skip = Plots._backend_skips[:plotlyjs])
# image_comparison_facts(:plotly, tol=IMG_TOL, skip = Plots._backend_skips[:plotlyjs])
# end
#
# pyplot()
# @testset "PyPlot" begin
# image_comparison_facts(:pyplot, tol=img_tol, skip = Plots._backend_skips[:pyplot])
# image_comparison_facts(:pyplot, tol=IMG_TOL, skip = Plots._backend_skips[:pyplot])
# end
#
# pgfplotsx()
# @testset "PGFPlotsX" begin
# image_comparison_facts(:pgfplotsx, tol=img_tol, skip = Plots._backend_skips[:pgfplotsx])
# image_comparison_facts(:pgfplotsx, tol=IMG_TOL, skip = Plots._backend_skips[:pgfplotsx])
# end
# 10 Histogram2D
@@ -83,7 +83,7 @@ img_tol = is_ci() ? 1e-2 : Sys.islinux() ? 1e-3 : 0.1
@static if haskey(ENV, "APPVEYOR")
@info "Skipping GR image comparison tests on AppVeyor"
else
image_comparison_facts(:gr, tol=img_tol, skip = Plots._backend_skips[:gr])
image_comparison_facts(:gr, tol=IMG_TOL, skip = Plots._backend_skips[:gr])
end
end
+3 -7
View File
@@ -314,16 +314,12 @@ end
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 length(plots) == 3
@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