Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for "segmented" attributes with NaNs #3320

Merged
merged 9 commits into from
Mar 2, 2021
13 changes: 5 additions & 8 deletions deps/SnoopCompile/precompile/precompile_Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function _precompile_()
Base.precompile(Tuple{Core.kwftype(typeof(Type)),NamedTuple{(:parent,),Tuple{Subplot{PlotlyBackend}}},Type{Subplot},PlotlyBackend})
Base.precompile(Tuple{Core.kwftype(typeof(_make_hist)),NamedTuple{(:normed, :weights),Tuple{Bool,Array{Int64,1}}},typeof(_make_hist),Tuple{Array{Float64,1}},Symbol})
Base.precompile(Tuple{Core.kwftype(typeof(_make_hist)),NamedTuple{(:normed, :weights),Tuple{Bool,Nothing}},typeof(_make_hist),Tuple{Array{Float64,1},Array{Float64,1}},Int64})
Base.precompile(Tuple{Core.kwftype(typeof(_make_hist)),NamedTuple{(:normed, :weights),Tuple{Bool,Nothing}},typeof(_make_hist),Tuple{Array{Float64,1},Array{Float64,1}},Tuple{Int64,Int64}})
Base.precompile(Tuple{Core.kwftype(typeof(_make_hist)),NamedTuple{(:normed, :weights),Tuple{Bool,Nothing}},typeof(_make_hist),Tuple{Array{Float64,1}},Symbol})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:flip,),Tuple{Bool}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:formatter,),Tuple{Symbol}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:formatter,),Tuple{typeof(datetimeformatter)}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:grid, :lims),Tuple{Bool,Tuple{Float64,Float64}}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:grid, :lims, :flip),Tuple{Bool,Tuple{Float64,Float64},Bool}},typeof(attr!),Axis})
Expand All @@ -74,7 +74,6 @@ function _precompile_()
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:lims,),Tuple{Tuple{Int64,Int64}}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:rotation,),Tuple{Int64}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:scale, :guide),Tuple{Symbol,String}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:ticks,),Tuple{Nothing}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(attr!)),NamedTuple{(:ticks,),Tuple{UnitRange{Int64}}},typeof(attr!),Axis})
Base.precompile(Tuple{Core.kwftype(typeof(default)),NamedTuple{(:titlefont, :legendfontsize, :guidefont, :tickfont, :guide, :framestyle, :yminorgrid),Tuple{Tuple{Int64,String},Int64,Tuple{Int64,Symbol},Tuple{Int64,Symbol},String,Symbol,Bool}},typeof(default)})
Base.precompile(Tuple{Core.kwftype(typeof(gr_polyline)),NamedTuple{(:arrowside, :arrowstyle),Tuple{Symbol,Symbol}},typeof(gr_polyline),Array{Int64,1},Array{Float64,1}})
Expand Down Expand Up @@ -141,14 +140,14 @@ function _precompile_()
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:m, :lab, :bg, :xlim, :ylim, :seriestype),Tuple{Tuple{Int64,Symbol},Array{String,2},Symbol,Tuple{Int64,Int64},Tuple{Int64,Int64},Symbol}},typeof(plot),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,2}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:marker,),Tuple{Bool}},typeof(plot),Array{Union{Missing, Int64},1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:marker_z, :color, :legend, :seriestype),Tuple{typeof(+),Symbol,Bool,Symbol}},typeof(plot),Array{Float64,1},Array{Float64,1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:markershape, :markersize, :marker_z, :line_z, :linewidth),Tuple{Array{Symbol,2},Array{Int64,2},Array{Int64,2},Array{Int64,2},Array{Int64,2}}},typeof(plot),Array{Float64,2}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:nbins, :seriestype),Tuple{Int64,Symbol}},typeof(plot),Array{Float64,1},Array{Float64,1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:nbins, :show_empty_bins, :normed, :aspect_ratio, :seriestype),Tuple{Tuple{Int64,Int64},Bool,Bool,Int64,Symbol}},typeof(plot),Array{Complex{Float64},1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:proj, :m),Tuple{Symbol,Int64}},typeof(plot),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:projection, :seriestype),Tuple{Symbol,Symbol}},typeof(plot),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},UnitRange{Int64},Vararg{Any,N} where N})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:quiver, :seriestype),Tuple{Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1}},Symbol}},typeof(plot),Array{Float64,1},Array{Float64,1},Vararg{Array{Float64,1},N} where N})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:reg, :fill),Tuple{Bool,Tuple{Int64,Symbol}}},typeof(plot),Array{Float64,1}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:ribbon,),Tuple{Int64}},typeof(plot),UnitRange{Int64}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:ribbon,),Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}},typeof(plot),UnitRange{Int64}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:ribbon,),Tuple{Tuple{LinRange{Float64},LinRange{Float64}}}},typeof(plot),UnitRange{Int64}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:ribbon,),Tuple{typeof(sqrt)}},typeof(plot),UnitRange{Int64}})
Base.precompile(Tuple{Core.kwftype(typeof(plot)),NamedTuple{(:seriestype, :markershape, :markersize, :color),Tuple{Array{Symbol,2},Array{Symbol,1},Int64,Array{Symbol,1}}},typeof(plot),Array{Float64,2}})
Expand Down Expand Up @@ -247,11 +246,12 @@ function _precompile_()
Base.precompile(Tuple{typeof(gr_draw_markers),Series,Base.OneTo{Int64},Array{Float64,1},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_markers),Series,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,1},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Array{Float64,1},Array{Float64,1},Int64,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Array{Float64,1},Array{Float64,1},Nothing,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Array{Int64,1},Array{Int64,1},Nothing,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Base.OneTo{Int64},Array{Float64,1},Int64,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Base.OneTo{Int64},Array{Float64,1},Nothing,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,Base.OneTo{Int64},UnitRange{Int64},Tuple{Array{Float64,1},Array{Float64,1}},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_segments),Series,StepRange{Int64,Int64},Array{Float64,1},Int64,Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_shapes),Series,Array{Float64,1},Array{Float64,1},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_surface),Series,Array{Float64,1},Array{Float64,1},Array{Float64,1},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_draw_surface),Series,Array{Float64,1},Array{Float64,1},Array{Float64,2},Tuple{Float64,Float64}})
Base.precompile(Tuple{typeof(gr_get_ticks_size),Tuple{Array{Float64,1},Array{Any,1}},Int64})
Expand All @@ -262,15 +262,11 @@ function _precompile_()
Base.precompile(Tuple{typeof(gr_polaraxes),Int64,Float64,Subplot{GRBackend}})
Base.precompile(Tuple{typeof(gr_polyline),Array{Float64,1},Array{Float64,1},Function})
Base.precompile(Tuple{typeof(gr_set_gradient),PlotUtils.ContinuousColorGradient})
Base.precompile(Tuple{typeof(gr_viewport_from_bbox),Subplot{GRBackend},BoundingBox{Tuple{Length{:mm,Float64},Length{:mm,Float64}},Tuple{Length{:mm,Float64},Length{:mm,Float64}}},Length{:mm,Float64},Length{:mm,Float64},Array{Float64,1}})
Base.precompile(Tuple{typeof(heatmap_edges),Array{Float64,1},Symbol})
Base.precompile(Tuple{typeof(heatmap_edges),Base.OneTo{Int64},Symbol})
Base.precompile(Tuple{typeof(heatmap_edges),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Symbol})
Base.precompile(Tuple{typeof(heatmap_edges),UnitRange{Int64},Symbol})
Base.precompile(Tuple{typeof(ignorenan_minimum),Array{Int64,1}})
Base.precompile(Tuple{typeof(iter_segments),Array{Float64,1},Array{Float64,1},UnitRange{Int64}})
Base.precompile(Tuple{typeof(iter_segments),Array{Float64,1}})
Base.precompile(Tuple{typeof(iter_segments),Base.OneTo{Int64},Array{Float64,1}})
Base.precompile(Tuple{typeof(layout_args),Int64})
Base.precompile(Tuple{typeof(make_fillrange_side),UnitRange{Int64},LinRange{Float64}})
Base.precompile(Tuple{typeof(optimal_ticks_and_labels),Subplot{GRBackend},Axis,StepRange{Int64,Int64}})
Expand Down Expand Up @@ -298,6 +294,7 @@ function _precompile_()
Base.precompile(Tuple{typeof(quiver_using_arrows),DefaultsDict})
Base.precompile(Tuple{typeof(quiver_using_hack),DefaultsDict})
Base.precompile(Tuple{typeof(reset_axis_defaults_byletter!)})
Base.precompile(Tuple{typeof(slice_arg),Array{Int64,2},Int64})
Base.precompile(Tuple{typeof(slice_arg),Array{Length{:mm,Float64},2},Int64})
Base.precompile(Tuple{typeof(slice_arg),Array{PlotUtils.ContinuousColorGradient,2},Int64})
Base.precompile(Tuple{typeof(slice_arg),Array{RGBA{Float64},2},Int64})
Expand Down
1 change: 1 addition & 0 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ const _pgfplotsx_marker = [
:rtriangle,
:cross,
:xcross,
:x,
:star5,
:pentagon,
:hline,
Expand Down
25 changes: 15 additions & 10 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ function gr_add_series(sp, series)
gr_draw_markers(series, x, y, clims)
end
elseif st === :shape
gr_draw_shapes(series, x, y, clims)
gr_draw_shapes(series, clims)
elseif st in (:path3d, :scatter3d)
gr_draw_segments_3d(series, x, y, z, clims)
if st === :scatter3d || series[:markershape] !== :none
Expand Down Expand Up @@ -1613,12 +1613,13 @@ end
function gr_draw_segments(series, x, y, fillrange, clims)
st = series[:seriestype]
if x !== nothing && length(x) > 1
segments = iter_segments(series, st)
segments = series_segments(series, st)
# do area fill
if fillrange !== nothing
GR.setfillintstyle(GR.INTSTYLE_SOLID)
fr_from, fr_to = (is_2tuple(fillrange) ? fillrange : (y, fillrange))
for (i, rng) in enumerate(segments)
for segment in segments
i, rng = segment.attr_index, segment.range
fc = get_fillcolor(series, clims, i)
gr_set_fillcolor(fc)
fx = _cycle(x, vcat(rng, reverse(rng)))
Expand All @@ -1630,7 +1631,8 @@ function gr_draw_segments(series, x, y, fillrange, clims)

# draw the line(s)
if st in (:path, :straightline)
for (i, rng) in enumerate(segments)
for segment in segments
i, rng = segment.attr_index, segment.range
lc = get_linecolor(series, clims, i)
gr_set_line(
get_linewidth(series, i), get_linestyle(series, i), lc, series
Expand All @@ -1648,8 +1650,9 @@ end
function gr_draw_segments_3d(series, x, y, z, clims)
if series[:seriestype] === :path3d && length(x) > 1
lz = series[:line_z]
segments = iter_segments(series, :path3d)
for (i, rng) in enumerate(segments)
segments = series_segments(series, :path3d)
for segment in segments
i, rng = segment.attr_index, segment.range
lc = get_linecolor(series, clims, i)
gr_set_line(
get_linewidth(series, i), get_linestyle(series, i), lc, series
Expand All @@ -1674,8 +1677,9 @@ function gr_draw_markers(

shapes = series[:markershape]
if shapes != :none
for (i, rng) in enumerate(iter_segments(series, :scatter))
rng = intersect(eachindex(x), rng)
for segment in series_segments(series, :scatter)
i = segment.attr_index
rng = intersect(eachindex(x), segment.range)
if !isempty(rng)
ms = get_thickness_scaling(series) * _cycle(msize, i)
msw = get_thickness_scaling(series) * _cycle(strokewidth, i)
Expand All @@ -1688,9 +1692,10 @@ function gr_draw_markers(
end
end

function gr_draw_shapes(series, x, y, clims)
function gr_draw_shapes(series, clims)
x, y = shape_data(series)
for (i,rng) in enumerate(iter_segments(x, y))
for segment in series_segments(series, :shape)
i, rng = segment.attr_index, segment.range
if length(rng) > 1
# connect to the beginning
rng = vcat(rng, rng[1])
Expand Down
5 changes: 3 additions & 2 deletions src/backends/pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ end

function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, opt)
# treat segments
segments = iter_segments(series, series[:seriestype])
segments = collect(series_segments(series, series[:seriestype]))
sf = opt[:fillrange]
for (i, rng) in enumerate(segments)
for segment in segments
i, rng = segment.attr_index, segment.range
segment_opt = PGFPlotsX.Options()
segment_opt = merge(segment_opt, pgfx_linestyle(opt, i))
if opt[:markershape] != :none
Expand Down
17 changes: 10 additions & 7 deletions src/backends/plotly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ function plotly_series(plt::Plot, series::Series)
end

function plotly_series_shapes(plt::Plot, series::Series, clims)
segments = iter_segments(series)
segments = collect(series_segments(series))
plotattributes_outs = Vector{KW}(undef, length(segments))

# TODO: create a plotattributes_out for each polygon
Expand All @@ -662,7 +662,8 @@ function plotly_series_shapes(plt::Plot, series::Series, clims)
for (letter, data) in zip((:x, :y), shape_data(series, 100))
)

for (i,rng) in enumerate(segments)
for segment in segments
i, rng = segment.attr_index, segment.range
length(rng) < 2 && continue

# to draw polygons, we actually draw lines with fill
Expand Down Expand Up @@ -705,14 +706,16 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z
hasfillrange = st in (:path, :scatter, :scattergl, :straightline) &&
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))

segments = iter_segments(series, st)
segments = collect(series_segments(series, st))
plotattributes_outs = fill(KW(), (hasfillrange ? 2 : 1 ) * length(segments))

needs_scatter_fix = !isscatter && hasmarker && !any(isnan,y) && length(segments) > 1

for (i,rng) in enumerate(segments)
for (k, segment) in enumerate(segments)
i, rng = segment.attr_index, segment.range

plotattributes_out = deepcopy(plotattributes_base)
plotattributes_out[:showlegend] = i==1 ? should_add_to_legend(series) : false
plotattributes_out[:showlegend] = k==1 ? should_add_to_legend(series) : false
plotattributes_out[:legendgroup] = series[:label]

# set the type
Expand Down Expand Up @@ -805,9 +808,9 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z
delete!(plotattributes_out, :fillcolor)
end

plotattributes_outs[(2 * i - 1):(2 * i)] = [plotattributes_out_fillrange, plotattributes_out]
plotattributes_outs[(2k-1):(2k)] = [plotattributes_out_fillrange, plotattributes_out]
else
plotattributes_outs[i] = plotattributes_out
plotattributes_outs[k] = plotattributes_out
end
end

Expand Down
14 changes: 9 additions & 5 deletions src/backends/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# end
# push!(handles, handle)
# else
for (i, rng) in enumerate(iter_segments(series, st))
for (k, segment) in enumerate(series_segments(series, st))
i, rng = segment.attr_index, segment.range
handle = ax."plot"((arg[rng] for arg in xyargs)...;
label = i == 1 ? series[:label] : "",
label = k == 1 ? series[:label] : "",
zorder = series[:series_plotindex],
color = py_color(single_color(get_linecolor(series, clims, i)), get_linealpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
Expand Down Expand Up @@ -486,7 +487,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
if series[:markershape] != :none && st in (
:path, :scatter, :path3d, :scatter3d, :steppre, :steppost, :bar
)
for (i, rng) in enumerate(iter_segments(series, :scatter))
for segment in series_segments(series, :scatter)
i, rng = segment.attr_index, segment.range
xyargs = if st == :bar && !isvertical(series)
if RecipesPipeline.is3d(sp)
y[rng], x[rng], z[rng]
Expand Down Expand Up @@ -679,7 +681,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)

if st == :shape
handle = []
for (i, rng) in enumerate(iter_segments(series))
for segment in series_segments(series)
i, rng = segment.attr_index, segment.range
if length(rng) > 1
path = pypath."Path"(hcat(x[rng], y[rng]))
patches = pypatches."PathPatch"(
Expand All @@ -706,7 +709,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# handle area filling
fillrange = series[:fillrange]
if fillrange !== nothing && st != :contour
for (i, rng) in enumerate(iter_segments(series))
for segment in series_segments(series)
i, rng = segment.attr_index, segment.range
f, dim1, dim2 = if isvertical(series)
:fill_between, x[rng], y[rng]
else
Expand Down
12 changes: 4 additions & 8 deletions src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@ function coords(shape::Shape)
shape.x, shape.y
end

#coords(shapes::AVec{Shape}) = unzip(map(coords, shapes))
function coords(shapes::AVec{Shape})
length(shapes) == 0 && return zeros(0), zeros(0)
xs = map(get_xs, shapes)
ys = map(get_ys, shapes)
x, y = map(copy, coords(shapes[1]))
for shape in shapes[2:end]
nanappend!(x, shape.x)
nanappend!(y, shape.y)
end
c = map(coords, shapes)
x = [q[1] for q in c]
y = [q[2] for q in c]
x, y
end

Expand Down
17 changes: 15 additions & 2 deletions src/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1031,13 +1031,26 @@ const _examples = PlotExample[
[quote
yv = ones(9)
ys = [1; 1; NaN; ones(6)]
plot(
5 .- [yv 2ys 3yv 4ys],
y = 5 .- [yv 2ys 3yv 4ys]

plt_color_rows = plot(
y,
seriestype = [:path :path :scatter :scatter],
markershape = [:utriangle, :rect],
markersize = 8,
color = [:red, :black],
)

plt_z_cols = plot(
y,
markershape = [:utriangle :x :circle :square],
markersize = [5 10 10 5],
marker_z = [5 4 3 2],
line_z = [1 3 3 1],
linewidth = [1 10 5 1]
)

plot(plt_color_rows, plt_z_cols)
end]
),
PlotExample( # 49
Expand Down
10 changes: 10 additions & 0 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,16 @@ end

@recipe function f(shapes::AVec{Shape})
seriestype --> :shape
# For backwards compatibility, column vectors of segmenting attributes are
# interpreted as having one element per shape
for attr in union(_segmenting_array_attributes, _segmenting_vector_attributes)
v = get(plotattributes, attr, nothing)
if v isa AVec || v isa AMat && size(v,2) == 1
@warn "Column vector attribute `$attr` reinterpreted as row vector (one value per shape).\n" *
"Pass a row vector instead (e.g. using `permutedims`) to suppress this warning."
plotattributes[attr] = permutedims(v)
end
end
coords(shapes)
end

Expand Down
Loading