Skip to content

Commit 00b68ef

Browse files
authored
polish Makie defaults and propagate :gap attributes (#144)
* polish Makie defaults and propagate `:gap` attributes * improve error Pattern
1 parent d4ee6b6 commit 00b68ef

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

docs/src/notebooks/makie_plotting.jl

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

225225
# ╔═╡ fae56f0f-bac4-4dea-b33c-d45e6f3b51fc
226226
let
227-
f, a, p = stackedhist([h1, h1]; error_color=Pattern('/'))
227+
f, a, p = stackedhist([h1, h1]; error_color=Pattern('/'; width=0.5, tilesize=(4,4)))
228228
f
229229
end
230230

ext/FHistMakieExt.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131

3232

3333
"""
34-
stackedhist(hs:AbstractVector{<:Hist1D}; errors=true|:bar|:shade, color=Makie.wong_colors())
34+
stackedhist(hs:AbstractVector{<:Hist1D}; errors=true|:bar|:shade, color=Makie.wong_colors(), gap=-0.01)
3535
3636
Plot a vector of 1D histograms stacked, use `errors` to show or hide error bar in the plot.
3737
`errors = true` and `errors = :bar` are equivalent.
@@ -52,14 +52,18 @@ title = "Processes"
5252
Legend(fig[1,2], elements, labels, title)
5353
fig
5454
```
55+
56+
!!! note
57+
The `gap` attribute is used to control the gap between the bars, it is set to `-0.01` by default to supress
58+
artifacts in Cairo backend.
5559
"""
5660
@recipe(StackedHist) do scene
5761
Attributes(
5862
error_color = (:black, 0.5),
5963
color = Makie.wong_colors(),
6064
labels = nothing,
6165
whiskerwidth = 10,
62-
gap = 0
66+
gap = -0.01
6367
)
6468
end
6569

@@ -83,19 +87,19 @@ function Makie.plot!(input::StackedHist{<:Tuple{AbstractVector{<:Hist1D}}})
8387
Makie.barplot!(input, xs, ys;
8488
stack = grp,
8589
color = c[grp],
86-
gap = 0,
90+
gap = input[:gap],
8791
)
8892

8993
error_color = input[:error_color]
9094
if error_color (true, :bar)
9195
errorbars!(input, centers, totals, errs/2, whiskerwidth = input[:whiskerwidth])
9296
else
9397
crossbar!(input, centers, totals, totals .+ errs/2, totals .- errs/2;
94-
gap = 0,
95-
width = diff(_e),
96-
show_midline = false,
97-
color = error_color
98-
)
98+
gap = input[:gap],
99+
width = diff(_e),
100+
show_midline = false,
101+
color = error_color
102+
)
99103
end
100104
input
101105
end
@@ -111,6 +115,7 @@ Plot a histogram that represents a ratio (i.e. `h = h1/h3`), you can pass `color
111115
Attributes(
112116
errors = true,
113117
whiskerwidth = 10,
118+
color = :black
114119
)
115120
end
116121

@@ -119,7 +124,7 @@ function Makie.plot!(input::RatioHist{<:Tuple{<:Hist1D}})
119124
xs = bincenters(hratio)
120125
ys = bincounts(hratio)
121126

122-
color = input[:color][]
127+
color = input[:color]
123128

124129
scatter!(input, xs, ys; color=color)
125130
if input[:errors][]
@@ -200,7 +205,6 @@ function Makie.plot!(plot::Hist{<:Tuple{<:Hist1D}})
200205
for key in keys(attributes)
201206
attributes[key] = get(plot.attributes, key, attributes[key])
202207
end
203-
attributes[:gap][] = 0
204208
attributes[:fillto][] = eps()
205209
myhist = plot[1]
206210
attributes[:width][] = diff(binedges(myhist[]))

0 commit comments

Comments
 (0)