Skip to content

Commit fcf8321

Browse files
authored
Fix secondary color (#518)
* Fix secondary color * remove placeholder
1 parent e23c050 commit fcf8321

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ end
277277

278278
errorline(1:10, y[:,:,1], errorstyle=:ribbon, label="Ribbon")
279279
errorline!(1:10, y[:,:,2], errorstyle=:stick, label="Stick", secondarycolor=:matched)
280-
errorline!(1:10, y[:,:,3], errorstyle=:spaghetti, label="Spaghetti")
280+
errorline!(1:10, y[:,:,3], errorstyle=:plume, label="Plume")
281281
```
282282

283283
<img width="575" alt="ErrorLine Styles" src="https://user-images.githubusercontent.com/24966610/186655231-2b7b9e37-0beb-4796-ad08-cbb84020ffd8.svg">

src/errorline.jl

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,26 @@ end
117117
end
118118
end
119119

120+
# Determine if a color palette is being used so it can be passed to secondary lines
121+
if :color_palette keys(plotattributes)
122+
color_palette = :default
123+
else
124+
color_palette = plotattributes[:color_palette]
125+
end
126+
120127
# Parse different color type
121128
if groupcolor isa Symbol || groupcolor isa RGB{Float64} || groupcolor isa RGBA{Float64}
122129
groupcolor = [groupcolor]
123130
end
131+
124132
# Check groupcolor format
125133
if (groupcolor !== nothing && ndims(y) > 2) && length(groupcolor) == 1
126134
groupcolor = repeat(groupcolor, size(y,3)) # Use the same color for all groups
127135
elseif (groupcolor !== nothing && ndims(y) > 2) && length(groupcolor) < size(y,3)
128136
error("$(length(groupcolor)) colors given for a matrix with $(size(y,3)) groups")
129-
end
130-
# Determine if a color palette is being used so it can be passed to secondary lines
131-
if :color_palette keys(plotattributes)
132-
color_palette = :default
133-
else
134-
color_palette = plotattributes[:color_palette]
137+
elseif groupcolor === nothing
138+
group_series_index = length(plotattributes[:plot_object]) + 1
139+
groupcolor = palette(color_palette)[group_series_index:group_series_index+size(y,3)]
135140
end
136141

137142
if errorstyle == :plume && numsecondarylines > size(y,2) # Override numsecondarylines
@@ -141,17 +146,16 @@ end
141146
for g = axes(y,3) # Iterate through 3rd dimension
142147
# Compute center and distribution for each value of x
143148
y_central, y_error = compute_error(y[:,:,g], centertype, errortype, percentiles)
149+
144150
if errorstyle == :ribbon
145151
seriestype := :path
146152
@series begin
147153
x := x
148154
y := y_central
149155
ribbon := y_error
150156
fillalpha --> .1
151-
if groupcolor !== nothing
152-
linecolor := groupcolor[g]
153-
fillcolor := groupcolor[g]
154-
end
157+
linecolor := groupcolor[g]
158+
fillcolor := groupcolor[g]
155159
() # Supress implicit return
156160
end
157161

@@ -172,11 +176,7 @@ end
172176
if secondarycolor === nothing
173177
linecolor := :gray60
174178
elseif secondarycolor == :matched
175-
if groupcolor !== nothing
176-
linecolor := groupcolor[g]
177-
else
178-
linecolor := palette(color_palette)[plotattributes[:plot_object][1][end][:series_index]+1]
179-
end
179+
linecolor := groupcolor[g]
180180
else
181181
linecolor := secondarycolor
182182
end
@@ -191,9 +191,7 @@ end
191191
primary := true
192192
x := x
193193
y := y_central
194-
if groupcolor !== nothing
195-
linecolor := groupcolor[g]
196-
end
194+
linecolor := groupcolor[g]
197195
()
198196
end
199197

@@ -213,9 +211,7 @@ end
213211
x := x
214212
y := y_sub_sample[:,i]
215213
# Set the stick color
216-
if groupcolor === nothing && (secondarycolor === nothing || secondarycolor == :matched)
217-
linecolor := palette(color_palette)[plotattributes[:plot_object][1][end][:series_index]+1]
218-
elseif groupcolor !== nothing && (secondarycolor == :matched || secondarycolor === nothing)
214+
if secondarycolor === nothing || secondarycolor == :matched
219215
linecolor := groupcolor[g]
220216
else
221217
linecolor := secondarycolor
@@ -227,14 +223,12 @@ end
227223
end
228224

229225
# Base line
230-
seriestype := :line
226+
seriestype := :path
231227
@series begin
232228
primary := true
233229
x := x
234230
y := y_central
235-
if groupcolor !== nothing
236-
linecolor := groupcolor[g]
237-
end
231+
linecolor := groupcolor[g]
238232
linewidth --> 3 # Make it stand out against the plume better
239233
()
240234
end

0 commit comments

Comments
 (0)