From b28eb5f7abfcb974fdd1939752dcf0ea565433e8 Mon Sep 17 00:00:00 2001 From: jkrumbiegel <22495855+jkrumbiegel@users.noreply.github.com> Date: Sun, 17 Jan 2021 11:38:59 +0100 Subject: [PATCH] rename histogram to hist to be able to export it, add docs (#599) --- docs/src/plotting_functions.md | 22 ++++++++++++++++++++++ src/AbstractPlotting.jl | 2 +- src/stats/{histogram.jl => hist.jl} | 18 +++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) rename src/stats/{histogram.jl => hist.jl} (87%) diff --git a/docs/src/plotting_functions.md b/docs/src/plotting_functions.md index 4dcdf82e0..bdd127692 100644 --- a/docs/src/plotting_functions.md +++ b/docs/src/plotting_functions.md @@ -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 diff --git a/src/AbstractPlotting.jl b/src/AbstractPlotting.jl index f82c7fc47..fe9324f07 100644 --- a/src/AbstractPlotting.jl +++ b/src/AbstractPlotting.jl @@ -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") diff --git a/src/stats/histogram.jl b/src/stats/hist.jl similarity index 87% rename from src/stats/histogram.jl rename to src/stats/hist.jl index 9eee59606..f476726e2 100644 --- a/src/stats/histogram.jl +++ b/src/stats/hist.jl @@ -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`. @@ -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] @@ -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 @@ -81,7 +77,3 @@ function AbstractPlotting.plot!(plot::Histogram) plot end - -end - -using .HistogramNoExport \ No newline at end of file