added density recipe
This commit is contained in:
parent
6bfa31a89f
commit
60d97ad9c9
@ -174,7 +174,7 @@ supportedMarkers(::AbstractBackend) = [:none]
|
|||||||
supportedScales(::AbstractBackend) = [:identity]
|
supportedScales(::AbstractBackend) = [:identity]
|
||||||
subplotSupported(::AbstractBackend) = false
|
subplotSupported(::AbstractBackend) = false
|
||||||
stringsSupported(::AbstractBackend) = false
|
stringsSupported(::AbstractBackend) = false
|
||||||
nativeImagesSupported(::AbstractBackend) = false
|
nativeImagesSupported(b::AbstractBackend) = :image in supportedTypes(b)
|
||||||
|
|
||||||
supportedAxes() = supportedAxes(backend())
|
supportedAxes() = supportedAxes(backend())
|
||||||
supportedTypes() = supportedTypes(backend())
|
supportedTypes() = supportedTypes(backend())
|
||||||
|
|||||||
@ -52,7 +52,7 @@ supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdo
|
|||||||
supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
|
supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
|
||||||
supportedScales(::GRBackend) = [:identity, :log10]
|
supportedScales(::GRBackend) = [:identity, :log10]
|
||||||
subplotSupported(::GRBackend) = true
|
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]))
|
GR.settextcolorind(gr_getcolorind(xaxis[:foreground_color_text]))
|
||||||
|
|
||||||
if axes_2d
|
if axes_2d
|
||||||
|
# draw the grid lines
|
||||||
GR.setlinewidth(1)
|
GR.setlinewidth(1)
|
||||||
# GR.setlinetype(GR.LINETYPE_DOTTED)
|
# 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
|
if grid_flag
|
||||||
|
GR.setlinecolorind(gr_getcolorind(sp[:foreground_color_grid]))
|
||||||
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
# @show dark_bg, xtick, ytick, majorx, majory
|
# @show dark_bg, xtick, ytick, majorx, majory
|
||||||
# if dark_bg
|
# 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)
|
# GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ticksize = 0.0075 * window_diag
|
||||||
|
if outside_ticks
|
||||||
|
ticksize = -ticksize
|
||||||
|
end
|
||||||
# TODO: this should be done for each axis separately
|
# TODO: this should be done for each axis separately
|
||||||
GR.setlinecolorind(gr_getcolorind(xaxis[:foreground_color_axis]))
|
GR.setlinecolorind(gr_getcolorind(xaxis[:foreground_color_axis]))
|
||||||
if num_axes == 1
|
if num_axes == 1
|
||||||
|
|||||||
@ -49,7 +49,7 @@ supportedStyles(::PyPlotBackend) = [:auto, :solid, :dash, :dot, :dashdot]
|
|||||||
supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape)
|
supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape)
|
||||||
supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10]
|
supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10]
|
||||||
subplotSupported(::PyPlotBackend) = true
|
subplotSupported(::PyPlotBackend) = true
|
||||||
nativeImagesSupported(::PyPlotBackend) = true
|
# nativeImagesSupported(::PyPlotBackend) = true
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -361,12 +361,14 @@ function my_hist(v, bins; normed = false, weights = nothing)
|
|||||||
edges = calc_edges(v, bins)
|
edges = calc_edges(v, bins)
|
||||||
counts = zeros(length(edges)-1)
|
counts = zeros(length(edges)-1)
|
||||||
|
|
||||||
|
# add a weighted count
|
||||||
for (i,vi) in enumerate(v)
|
for (i,vi) in enumerate(v)
|
||||||
idx = bucket_index(vi, edges)
|
idx = bucket_index(vi, edges)
|
||||||
counts[idx] += (weights == nothing ? 1.0 : weights[i])
|
counts[idx] += (weights == nothing ? 1.0 : weights[i])
|
||||||
end
|
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
|
if norm_denom == 0
|
||||||
norm_denom = 1.0
|
norm_denom = 1.0
|
||||||
end
|
end
|
||||||
@ -395,13 +397,15 @@ function my_hist_2d(x, y, bins; normed = false, weights = nothing)
|
|||||||
xedges, yedges = calc_edges_2d(x, y, bins)
|
xedges, yedges = calc_edges_2d(x, y, bins)
|
||||||
counts = zeros(length(yedges)-1, length(xedges)-1)
|
counts = zeros(length(yedges)-1, length(xedges)-1)
|
||||||
|
|
||||||
|
# add a weighted count
|
||||||
for i=1:length(x)
|
for i=1:length(x)
|
||||||
r = bucket_index(y[i], yedges)
|
r = bucket_index(y[i], yedges)
|
||||||
c = bucket_index(x[i], xedges)
|
c = bucket_index(x[i], xedges)
|
||||||
counts[r,c] += (weights == nothing ? 1.0 : weights[i])
|
counts[r,c] += (weights == nothing ? 1.0 : weights[i])
|
||||||
end
|
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
|
if norm_denom == 0
|
||||||
norm_denom = 1.0
|
norm_denom = 1.0
|
||||||
end
|
end
|
||||||
@ -477,13 +481,13 @@ end
|
|||||||
# otherwise, just use a histogram
|
# otherwise, just use a histogram
|
||||||
if is_installed("KernelDensity")
|
if is_installed("KernelDensity")
|
||||||
@eval import KernelDensity
|
@eval import KernelDensity
|
||||||
@eval function violin_coords(y)
|
@eval function violin_coords(y, bins = 30)
|
||||||
kd = KernelDensity.kde(y, npoints = 30)
|
kd = KernelDensity.kde(y, npoints = isa(bins, Integer) ? bins : 30)
|
||||||
kd.density, kd.x
|
kd.density, kd.x
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@eval function violin_coords(y)
|
@eval function violin_coords(y, bins = 30)
|
||||||
edges, widths = hist(y, 20)
|
edges, widths = hist(y, isa(bins, Integer) ? bins : 30)
|
||||||
centers = 0.5 * (edges[1:end-1] + edges[2:end])
|
centers = 0.5 * (edges[1:end-1] + edges[2:end])
|
||||||
ymin, ymax = extrema(y)
|
ymin, ymax = extrema(y)
|
||||||
vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax)
|
vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax)
|
||||||
@ -526,6 +530,21 @@ end
|
|||||||
# KW[d]
|
# KW[d]
|
||||||
end
|
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
|
# Error Bars
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user