Skip to content

Commit ebbc9c9

Browse files
more fixes
1 parent 12cbab3 commit ebbc9c9

File tree

9 files changed

+54
-31
lines changed

9 files changed

+54
-31
lines changed

PlotsBase/ext/PGFPlotsXExt.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,15 +1271,25 @@ end
12711271
function pgfx_fillrange_attrs(fillrange, x, y)
12721272
n = length(x)
12731273
x_fill = [x; x[n:-1:1]; x[1]]
1274-
y_fill = [y; _getvalue(fillrange, n:-1:1); y[1]]
1274+
fr_vals = if fillrange isa Number
1275+
fill(fillrange, n)
1276+
else
1277+
_getvalue(fillrange, n:-1:1)
1278+
end
1279+
y_fill = [y; fr_vals; y[1]]
12751280
return PGFPlotsX.Coordinates(x_fill, y_fill)
12761281
end
12771282

12781283
function pgfx_fillrange_attrs(fillrange, x, y, z)
12791284
n = length(x)
12801285
x_fill = [x; x[n:-1:1]; x[1]]
1281-
y_fill = [y; y[n:-1:1]; x[1]]
1282-
z_fill = [z; _getvalue(fillrange, n:-1:1); z[1]]
1286+
y_fill = [y; y[n:-1:1]; y[1]]
1287+
fr_vals = if fillrange isa Number
1288+
fill(fillrange, n)
1289+
else
1290+
_getvalue(fillrange, n:-1:1)
1291+
end
1292+
z_fill = [z; fr_vals; z[1]]
12831293
return PGFPlotsX.Coordinates(x_fill, y_fill, z_fill)
12841294
end
12851295

PlotsBase/src/Commons/Commons.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,7 @@ end
293293

294294
# helpers to figure out if there are NaN values in a list of array types
295295
anynan(i::Int, args::Tuple) = any(
296-
a -> try
297-
isnan(_getvalue(a, i))
298-
catch MethodError
299-
false
300-
end, args
296+
a -> isnan(_getvalue(a, i)), args
301297
)
302298
anynan(args::Tuple) = i -> anynan(i, args)
303299
anynan(istart::Int, iend::Int, args::Tuple) = any(anynan(args), istart:iend)

PlotsBase/src/DataSeries.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ for comp in (:line, :fill, :marker)
153153
isa(c, PlotUtils.ColorGradient) ? c : PlotUtils.plot_color(c)
154154
else
155155
grad = _getattr(series, $Symbol($compcolor)) # series[:linecolor], series[:fillcolor], series[:markercolor]
156-
if s :identity
156+
if !(grad isa PlotUtils.ColorGradient)
157+
# z-coloring requires a gradient; if a plain color, just return it
158+
PlotUtils.plot_color(grad)
159+
elseif s :identity
157160
get(grad, z, (cmin, cmax))
158161
else
159162
base = _log_scale_bases[s]

PlotsBase/src/Subplots.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ Commons.get_ticks(sp::Subplot, s::Symbol) = get_ticks(sp, sp[get_attr_symbol(s,
8888
# converts a symbol or string into a Colorant or ColorGradient
8989
# and assigns a color automatically
9090
function get_series_color(c, sp::Subplot, n::Int, seriestype)
91+
# Ensure valid index (n can be 0 for non-primary series before any primary series)
92+
idx = max(1, n)
9193
c = if c :auto
92-
Commons.like_surface(seriestype) ? PlotsBase.cgrad() : _getattr(sp, :color_palette, n)
94+
Commons.like_surface(seriestype) ? PlotsBase.cgrad() : _getattr(sp, :color_palette, idx)
9395
elseif isa(c, Int)
9496
_getattr(sp, :color_palette, c)
9597
elseif c isa RecipesBase.CyclingAttribute
96-
c[n]
98+
c[idx]
9799
else
98100
c
99101
end

PlotsBase/src/recipes.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,30 @@ end
682682

683683
# create a secondary series for the markers
684684
if plotattributes[:markershape] :none
685+
# create the primary path series first
685686
@series begin
686-
seriestype := :scatter
687-
x := _bin_centers(edge)
688-
y := weights
689-
fillrange := nothing
690-
label := ""
691-
primary := false
687+
x := xpts
688+
y := ypts
689+
seriestype := :path
690+
markershape := :none
691+
xerror := :none
692+
yerror := :none
692693
()
693694
end
694-
markershape := :none
695-
xerror := :none
696-
yerror := :none
695+
# then the non-primary scatter series for markers
696+
seriestype := :scatter
697+
x := _bin_centers(edge)
698+
y := weights
699+
fillrange := nothing
700+
label := ""
701+
primary := false
702+
()
703+
else
704+
x := xpts
705+
y := ypts
706+
seriestype := :path
707+
()
697708
end
698-
699-
x := xpts
700-
y := ypts
701-
seriestype := :path
702-
()
703709
end
704710
@deps stepbins path
705711

PlotsBase/test/test_pgfplotsx.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Test, PlotsBase, Unitful, LaTeXStrings
2+
using RecipesBase: cycle
23
const PGFPlotsX = Base.get_extension(PlotsBase, :PGFPlotsXExt).PGFPlotsX
34

45
function create_plot(args...; kwargs...)
@@ -71,7 +72,7 @@ with(:pgfplotsx) do
7172
rand(11, 4),
7273
lab = "lines",
7374
w = 3,
74-
palette = :grays,
75+
palette = cycle(:grays),
7576
fill = 0,
7677
α = 0.6,
7778
)
@@ -134,7 +135,7 @@ with(:pgfplotsx) do
134135
@test plot(
135136
PlotsBase.fakedata(100, 10),
136137
layout = 4,
137-
palette = [:grays :blues :hot :rainbow],
138+
palette = cycle.([:grays :blues :hot :rainbow]),
138139
bg_inside = [:orange :pink :darkblue :black],
139140
) isa PlotsBase.Plot
140141
end
@@ -347,9 +348,9 @@ with(:pgfplotsx) do
347348
@testset "Markers and Paths" begin
348349
pl = plot(
349350
5 .- ones(9),
350-
markershape = [:utriangle, :rect],
351+
markershape = cycle([:utriangle, :rect]),
351352
markersize = 8,
352-
color = [:red, :black],
353+
color = cycle([:red, :black]),
353354
)
354355
axis_contents = first(get_pgf_axes(pl)).contents
355356
plots = filter(x -> x isa PGFPlotsX.Plot, axis_contents)

PlotsBase/test/test_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ end
155155
@test segments([nan10; 1:5]) == [11:15]
156156
@test segments([1:5; nan10]) == [1:5]
157157
@test segments([nan10; 1:5; nan10; 1:5; nan10]) == [11:15, 26:30]
158-
@test segments([NaN; 1], 1:10) == [2:2, 4:4, 6:6, 8:8, 10:10]
158+
@test segments(RecipesBase.cycle([NaN; 1]), 1:10) == [2:2, 4:4, 6:6, 8:8, 10:10]
159159
@test segments([nan10; 1:15], [1:15; nan10]) == [11:15]
160160
end
161161

@@ -265,7 +265,7 @@ end
265265

266266
# test cycling indexes
267267
x = 0.0:0.1:1
268-
y = [1, 2, 3]
268+
y = RecipesBase.cycle([1, 2, 3])
269269
pl = scatter(x, y)
270270
@test PlotsBase._guess_best_legend_position(:best, pl) :topright
271271

RecipesBase/src/RecipesBase.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ for op in (:+, :-, :/, :*)
9595
end
9696
Base.:-(a::CyclingAttribute) = CyclingAttribute(-a.value)
9797
Base.:(==)(a::CyclingAttribute, b::CyclingAttribute) = a.value == b.value
98+
Base.firstindex(c::CyclingAttribute) = firstindex(c.value)
99+
Base.lastindex(c::CyclingAttribute) = lastindex(c.value)
100+
Base.length(c::CyclingAttribute) = length(c.value)
101+
Base.size(c::CyclingAttribute, args...) = size(c.value, args...)
98102
# --------------------------------------------------------------------------
99103

100104
@inline to_symbol(s::Symbol) = s

RecipesPipeline/src/series.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ _prepare_series_data(s::Surface{<:AMat{<:MaybeNumber}}) =
3232
_prepare_series_data(s::Surface) = s # non-numeric Surface, such as an image
3333
_prepare_series_data(v::Volume) =
3434
Volume(_prepare_series_data(v.v), v.x_extents, v.y_extents, v.z_extents)
35+
_prepare_series_data(c::RecipesBase.CyclingAttribute) = c
3536

3637
# default: assume x represents a single series
3738
_series_data_vector(x, plotattributes) = [_prepare_series_data(x)]

0 commit comments

Comments
 (0)