diff --git a/src/backends.jl b/src/backends.jl index 4ba64565..9d64f9c7 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -174,7 +174,7 @@ supportedMarkers(::AbstractBackend) = [:none] supportedScales(::AbstractBackend) = [:identity] subplotSupported(::AbstractBackend) = false stringsSupported(::AbstractBackend) = false -nativeImagesSupported(::AbstractBackend) = false +nativeImagesSupported(b::AbstractBackend) = :image in supportedTypes(b) supportedAxes() = supportedAxes(backend()) supportedTypes() = supportedTypes(backend()) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index fcb0f298..725b9672 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -52,7 +52,7 @@ supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdo supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape) supportedScales(::GRBackend) = [:identity, :log10] subplotSupported(::GRBackend) = true -nativeImagesSupported(::GRBackend) = true +# nativeImagesSupported(::GRBackend) = true @@ -722,14 +722,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.settextcolorind(gr_getcolorind(xaxis[:foreground_color_text])) if axes_2d + # draw the grid lines GR.setlinewidth(1) # GR.setlinetype(GR.LINETYPE_DOTTED) - GR.setlinecolorind(gr_getcolorind(sp[:foreground_color_grid])) - ticksize = 0.0075 * window_diag - if outside_ticks - ticksize = -ticksize - end if grid_flag + GR.setlinecolorind(gr_getcolorind(sp[:foreground_color_grid])) GR.grid(xtick, ytick, 0, 0, majorx, majory) # @show dark_bg, xtick, ytick, majorx, majory # if dark_bg @@ -738,6 +735,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # GR.grid(xtick, ytick, 0, 0, majorx, majory) # end end + + ticksize = 0.0075 * window_diag + if outside_ticks + ticksize = -ticksize + end # TODO: this should be done for each axis separately GR.setlinecolorind(gr_getcolorind(xaxis[:foreground_color_axis])) if num_axes == 1 diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index bbd0fb3e..af6c23ed 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -49,7 +49,7 @@ supportedStyles(::PyPlotBackend) = [:auto, :solid, :dash, :dot, :dashdot] supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape) supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10] subplotSupported(::PyPlotBackend) = true -nativeImagesSupported(::PyPlotBackend) = true +# nativeImagesSupported(::PyPlotBackend) = true # -------------------------------------------------------------------------------------- diff --git a/src/recipes.jl b/src/recipes.jl index f7027b41..5b8e9005 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -361,12 +361,14 @@ function my_hist(v, bins; normed = false, weights = nothing) edges = calc_edges(v, bins) counts = zeros(length(edges)-1) + # add a weighted count for (i,vi) in enumerate(v) idx = bucket_index(vi, edges) counts[idx] += (weights == nothing ? 1.0 : weights[i]) end - norm_denom = normed ? sum(counts) : 1.0 + # normalize by bar area? + norm_denom = normed ? sum(diff(edges) .* counts) : 1.0 if norm_denom == 0 norm_denom = 1.0 end @@ -395,13 +397,15 @@ function my_hist_2d(x, y, bins; normed = false, weights = nothing) xedges, yedges = calc_edges_2d(x, y, bins) counts = zeros(length(yedges)-1, length(xedges)-1) + # add a weighted count for i=1:length(x) r = bucket_index(y[i], yedges) c = bucket_index(x[i], xedges) counts[r,c] += (weights == nothing ? 1.0 : weights[i]) end - norm_denom = normed ? sum(counts) : 1.0 + # normalize to cubic area of the imaginary surface towers + norm_denom = normed ? sum((diff(yedges) * diff(xedges)') .* counts) : 1.0 if norm_denom == 0 norm_denom = 1.0 end @@ -477,13 +481,13 @@ end # otherwise, just use a histogram if is_installed("KernelDensity") @eval import KernelDensity - @eval function violin_coords(y) - kd = KernelDensity.kde(y, npoints = 30) + @eval function violin_coords(y, bins = 30) + kd = KernelDensity.kde(y, npoints = isa(bins, Integer) ? bins : 30) kd.density, kd.x end else - @eval function violin_coords(y) - edges, widths = hist(y, 20) + @eval function violin_coords(y, bins = 30) + edges, widths = hist(y, isa(bins, Integer) ? bins : 30) centers = 0.5 * (edges[1:end-1] + edges[2:end]) ymin, ymax = extrema(y) vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax) @@ -526,6 +530,21 @@ end # KW[d] end +# --------------------------------------------------------------------------- +# density + +@recipe function f(::Type{Val{:density}}, x, y, z) + newx, newy = violin_coords(y, d[:bins]) + if isvertical(d) + newx, newy = newy, newx + end + d[:x], d[:y] = newx, newy + seriestype := :path + () +end + + + # --------------------------------------------------------------------------- # Error Bars