Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
rename histogram to hist to be able to export it, add docs (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Jan 17, 2021
1 parent 1bbd2ab commit b28eb5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
22 changes: 22 additions & 0 deletions docs/src/plotting_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ zs = [cos(x) * sin(y) for x in xs, y in ys]
heatmap(xs, ys, zs)
```

## `hist`

```@docs
hist
```

### Examples

```julia
using GLMakie
AbstractPlotting.inline!(true) # hide

data = randn(1000)

f = Figure()
hist(f[1, 1], data, bins = 10)
hist(f[1, 2], data, bins = 20, color = :red, strokewidth = 1, strokecolor = :black)
hist(f[2, 1], data, bins = [-5, -2, -1, 0, 1, 2, 5], color = :gray)
hist(f[2, 2], data, normalization = :pdf)
f
```

## `image`

```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractPlotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ include("layouting/boundingbox.jl")
# more default recipes
# statistical recipes
include("stats/conversions.jl")
include("stats/histogram.jl")
include("stats/hist.jl")
include("stats/density.jl")
include("stats/distributions.jl")
include("stats/crossbar.jl")
Expand Down
18 changes: 5 additions & 13 deletions src/stats/histogram.jl → src/stats/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ function convert_arguments(P::Type{<:AbstractPlot}, h::StatsBase.Histogram{<:Any
to_plotspec(ptype, convert_arguments(ptype, map(f, h.edges)..., Float64.(h.weights)); kwargs...)
end

# recipes export by default, but histogram clashes and breaks e.g. StatsMakie and StatsBase
module HistogramNoExport

using ..AbstractPlotting
using AbstractPlotting: @recipe, ATTRIBUTES
import StatsBase

"""
histogram(values; bins = 15, normalization = :none)
hist(values; bins = 15, normalization = :none)
Plot a histogram of `values`. `bins` can be an `Int` to create that
number of equal-width bins over the range of `values`.
Expand All @@ -35,14 +31,15 @@ can be normalized by setting `normalization`. Possible values are:
## Attributes
$(ATTRIBUTES)
"""
@recipe(Histogram, values) do scene
@recipe(Hist, values) do scene
Attributes(
bins = 15, # Int or iterable of edges
normalization = :none
)
end

function AbstractPlotting.plot!(plot::Histogram)

function AbstractPlotting.plot!(plot::Hist)

values = plot[:values]

Expand Down Expand Up @@ -70,8 +67,7 @@ function AbstractPlotting.plot!(plot::Histogram)
widths = lift(diff, edges)

# plot the values, not the observables, to be in control of updating
bp = barplot!(plot, points[]; width = widths[], plot.attributes...).plots[1]

bp = barplot!(plot, points[]; width = widths[], plot.attributes...)

# update the barplot points without triggering, then trigger with `width`
on(widths) do w
Expand All @@ -81,7 +77,3 @@ function AbstractPlotting.plot!(plot::Histogram)

plot
end

end

using .HistogramNoExport

0 comments on commit b28eb5f

Please sign in to comment.