recompute_lengths fix; renamed hist to histogram, hist2d to histogram2d to match methods; fix tests

This commit is contained in:
Thomas Breloff 2016-05-27 15:08:05 -04:00
parent 536746d47e
commit 088543176f
18 changed files with 55 additions and 54 deletions

View File

@ -243,10 +243,10 @@ end
# bar!(args...; kw...) = plot!(args...; kw..., seriestype = :bar)
# barh(args...; kw...) = plot(args...; kw..., seriestype = :barh, orientation = :h)
# barh!(args...; kw...) = plot!(args...; kw..., seriestype = :barh, orientation = :h)
# histogram(args...; kw...) = plot(args...; kw..., seriestype = :hist)
# histogram!(args...; kw...) = plot!(args...; kw..., seriestype = :hist)
# histogram2d(args...; kw...) = plot(args...; kw..., seriestype = :hist2d)
# histogram2d!(args...; kw...) = plot!(args...; kw..., seriestype = :hist2d)
# histogram(args...; kw...) = plot(args...; kw..., seriestype = :histogram)
# histogram!(args...; kw...) = plot!(args...; kw..., seriestype = :histogram)
# histogram2d(args...; kw...) = plot(args...; kw..., seriestype = :histogram2d)
# histogram2d!(args...; kw...) = plot!(args...; kw..., seriestype = :histogram2d)
# density(args...; kw...) = plot(args...; kw..., seriestype = :density)
# density!(args...; kw...) = plot!(args...; kw..., seriestype = :density)
# heatmap(args...; kw...) = plot(args...; kw..., seriestype = :heatmap)

View File

@ -12,7 +12,7 @@ const _3dTypes = [
]
const _allTypes = vcat([
:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :hist2d, :hist3d, :density, :bar, :hline, :vline, #:ohlc,
:heatmap, :hexbin, :histogram, :histogram2d, :histogram3d, :density, :bar, :hline, :vline, #:ohlc,
:contour, :pie, :shape, :image #, :boxplot, :violin, :quiver,
], _3dTypes)
@ -32,7 +32,6 @@ const _allTypes = vcat([
:stem => :sticks,
:stems => :sticks,
:dots => :scatter,
:histogram => :hist,
:pdf => :density,
:contours => :contour,
:line3d => :path3d,
@ -47,9 +46,11 @@ const _allTypes = vcat([
:img => :image,
:imshow => :image,
:imagesc => :image,
:hist => :histogram,
:hist2d => :histogram2d,
)
like_histogram(seriestype::Symbol) = seriestype in (:hist, :density)
like_histogram(seriestype::Symbol) = seriestype in (:histogram, :density)
like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost)
like_surface(seriestype::Symbol) = seriestype in (:contour, :contour3d, :heatmap, :surface, :wireframe, :image)

View File

@ -60,7 +60,7 @@ supportedArgs(::BokehBackend) = [
# :levels,
]
supportedAxes(::BokehBackend) = [:auto, :left]
supportedTypes(::BokehBackend) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour]
supportedTypes(::BokehBackend) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :histogram2d, :hexbin, :histogram, :bar, :hline, :vline, :contour]
supportedStyles(::BokehBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::BokehBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::BokehBackend) = [:identity, :ln] #, :ln, :log2, :log10, :asinh, :sqrt]

View File

@ -27,7 +27,7 @@ supportedArgs(::GadflyBackend) = [
supportedAxes(::GadflyBackend) = [:auto, :left]
supportedTypes(::GadflyBackend) = [
:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :hist2d, :hexbin, :hist,
:scatter, :histogram2d, :hexbin, :histogram,
:bar, #:box, :violin, :quiver,
:hline, :vline, :contour, :shape
]
@ -73,9 +73,9 @@ function getLineGeom(d::KW)
xbins, ybins = maketuple(d[:bins])
if st == :hexb
Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins)
elseif st == :hist2d
elseif st == :histogram2d
Gadfly.Geom.histogram2d(xbincount = xbins, ybincount = ybins)
elseif st == :hist
elseif st == :histogram
Gadfly.Geom.histogram(bincount = xbins,
orientation = isvertical(d) ? :vertical : :horizontal,
position = d[:bar_position] == :stack ? :stack : :dodge)
@ -121,7 +121,7 @@ function getGadflyLineTheme(d::KW)
fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha])
Gadfly.Theme(;
default_color = (st in (:hist,:hist2d,:hexbin,:bar,:sticks) ? fc : lc),
default_color = (st in (:histogram,:histogram2d,:hexbin,:bar,:sticks) ? fc : lc),
line_width = (st == :sticks ? 1 : d[:linewidth]) * Gadfly.px,
# line_style = Gadfly.get_stroke_vector(d[:linestyle]),
lowlight_color = x->RGB(fc), # fill/ribbon
@ -160,7 +160,7 @@ function addGadflyLine!(plt::Plot, numlayers::Int, d::KW, geoms...)
addGadflyContColorScale(plt, d[:linecolor])
end
kwargs[:x] = d[st == :hist ? :y : :x]
kwargs[:x] = d[st == :histogram ? :y : :x]
kwargs[:y] = d[:y]
end
@ -300,7 +300,7 @@ function addGadflySeries!(plt::Plot, d::KW)
st = d[:seriestype]
# if st == :ohlc
# error("Haven't re-implemented after refactoring")
if st in (:hist2d, :hexbin) && (isa(d[:fillcolor], ColorGradient) || isa(d[:fillcolor], ColorFunction))
if st in (:histogram2d, :hexbin) && (isa(d[:fillcolor], ColorGradient) || isa(d[:fillcolor], ColorFunction))
push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:fillcolor], p))))
elseif st == :scatter && d[:markershape] == :none
d[:markershape] = :ellipse
@ -311,7 +311,7 @@ function addGadflySeries!(plt::Plot, d::KW)
prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), d, plt.attr, smooth...))
end
st in (:hist2d, :hexbin, :contour) || addToGadflyLegend(plt, d)
st in (:histogram2d, :hexbin, :contour) || addToGadflyLegend(plt, d)
# now save the layers that apply to this series
d[:gadflylayers] = layers

View File

@ -60,7 +60,7 @@ supportedArgs(::GLVisualizeBackend) = [
# :levels,
]
supportedAxes(::GLVisualizeBackend) = [:auto, :left]
supportedTypes(::GLVisualizeBackend) = [:surface] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
supportedTypes(::GLVisualizeBackend) = [:surface] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :histogram, :bar, :hline, :vline, :contour]
supportedStyles(::GLVisualizeBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GLVisualizeBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::GLVisualizeBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]

View File

@ -39,7 +39,7 @@ supportedArgs(::GRBackend) = [
supportedAxes(::GRBackend) = _allAxes
supportedTypes(::GRBackend) = [
:path, :steppre, :steppost,
:scatter, :hist2d, :hexbin,
:scatter, :histogram2d, :hexbin,
:sticks,
:hline, :vline, :heatmap, :pie, :image, #:ohlc,
:contour, :path3d, :scatter3d, :surface, :wireframe
@ -514,7 +514,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
axes_2d = true
for series in series_list(sp)
st = ispolar(sp) ? :polar : series.d[:seriestype]
if st in (:hist2d, :hexbin, :contour, :surface, :heatmap)
if st in (:histogram2d, :hexbin, :contour, :surface, :heatmap)
cmap = true
end
if st in (:pie, :polar, :surface, :wireframe, :path3d, :scatter3d)
@ -542,9 +542,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# end
# if st == :bar
# x, y = 1:length(d[:y]), d[:y]
# elseif st in [:hist, :density]
# elseif st in [:histogram, :density]
# x, y = Base.hist(d[:y], d[:bins])
# elseif st in [:hist2d, :hexbin]
# elseif st in [:histogram2d, :hexbin]
# E = zeros(length(d[:x]),2)
# E[:,1] = d[:x]
# E[:,2] = d[:y]
@ -743,7 +743,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
d = series.d
# idx = d[:series_plotindex]
st = d[:seriestype]
if st in (:hist2d, :hexbin, :contour, :surface, :wireframe, :heatmap)
if st in (:histogram2d, :hexbin, :contour, :surface, :wireframe, :heatmap)
# grad = isa(d[:fillcolor], ColorGradient) ? d[:fillcolor] : default_gradient()
# cs = [getColorZ(grad, z) for z in linspace(0, 1, 256)]
# for (i, c) in enumerate(cs)
@ -895,7 +895,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# # end
# # TODO: use recipe
# elseif st in [:hist, :density]
# elseif st in [:histogram, :density]
# edges, counts = Base.hist(d[:y], d[:bins])
# gr_barplot(series, edges, counts)
# # x, y = float(collect(h[1])), float(h[2])
@ -919,7 +919,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end
# TODO: use recipe
elseif st in [:hist2d, :hexbin]
elseif st in [:histogram2d, :hexbin]
E = zeros(length(d[:x]),2)
E[:,1] = d[:x]
E[:,2] = d[:y]

View File

@ -44,7 +44,7 @@ supportedArgs(::PGFPlotsBackend) = [
# :match_dimensions,
]
supportedAxes(::PGFPlotsBackend) = [:auto, :left]
supportedTypes(::PGFPlotsBackend) = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :hist2d, :ysticks, :xsticks, :contour]
supportedTypes(::PGFPlotsBackend) = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour]
supportedStyles(::PGFPlotsBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon] #vcat(_allMarkers, Shape)
supportedScales(::PGFPlotsBackend) = [:identity, :ln, :log2, :log10] # :asinh, :sqrt]
@ -184,7 +184,7 @@ function pgf_series(sp::Subplot, series::Series)
PGFPlots.Linear3
elseif st == :scatter
PGFPlots.Scatter
elseif st == :hist2d
elseif st == :histogram2d
PGFPlots.Histogram2
elseif st == :contour
PGFPlots.Contour

View File

@ -36,7 +36,7 @@ supportedArgs(::PlotlyBackend) = [
supportedAxes(::PlotlyBackend) = [:auto, :left]
supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost,
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:histogram2d, :histogram, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
supportedStyles(::PlotlyBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PlotlyBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
@ -449,7 +449,7 @@ function plotly_series(plt::Plot, series::Series)
d_out[:type] = "bar"
d_out[:x], d_out[:y] = x, y
elseif st == :hist2d
elseif st == :histogram2d
d_out[:type] = "histogram2d"
d_out[:x], d_out[:y] = x, y
if isa(d[:bins], Tuple)
@ -460,13 +460,13 @@ function plotly_series(plt::Plot, series::Series)
d_out[:nbinsx] = xbins
d_out[:nbinsy] = ybins
elseif st in (:hist, :density)
elseif st in (:histogram, :density)
d_out[:type] = "histogram"
isvert = isvertical(d)
d_out[isvert ? :x : :y] = y
d_out[isvert ? :nbinsx : :nbinsy] = d[:bins]
if st == :density
d_out[:histnorm] = "probability density"
d_out[:histogramnorm] = "probability density"
end
elseif st == :heatmap

View File

@ -66,7 +66,7 @@ supportedArgs(::PlotlyJSBackend) = [
]
supportedAxes(::PlotlyJSBackend) = [:auto, :left]
supportedTypes(::PlotlyJSBackend) = [:none, :line, :path, :scatter, :steppre, :steppost,
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:histogram2d, :histogram, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
supportedStyles(::PlotlyJSBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PlotlyJSBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,

View File

@ -40,7 +40,7 @@ supportedArgs(::PyPlotBackend) = [
supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotBackend) = [
:none, :line, :path, :steppre, :steppost, :shape,
:scatter, :hist2d, :hexbin, :hist, :density,
:scatter, :histogram2d, :hexbin, :histogram, :density,
:bar, :sticks, #:box, :violin, :quiver,
:hline, :vline, :heatmap, :pie, :image,
:contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
@ -567,7 +567,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
push!(handles, handle)
end
if st == :hist
if st == :histogram
handle = ax[:hist](y;
label = d[:label],
zorder = plt.n,
@ -583,7 +583,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
push!(handles, handle)
end
if st == :hist2d
if st == :histogram2d
handle = ax[:hist2d](x, y;
label = d[:label],
zorder = plt.n,
@ -1146,13 +1146,13 @@ function addPyPlotLegend(plt::Plot, sp::Subplot, ax)
# if get_subplot(series) === sp &&
# series.d[:label] != "" &&
# !(series.d[:seriestype] in (
# :hexbin,:hist2d,:hline,:vline,
# :hexbin,:histogram2d,:hline,:vline,
# :contour,:contour3d,:surface,:wireframe,
# :heatmap,:path3d,:scatter3d, :pie, :image))
for series in series_list(sp)
if should_add_to_legend(series)
# add a line/marker and a label
push!(handles, if series.d[:seriestype] == :hist
push!(handles, if series.d[:seriestype] == :histogram
PyPlot.plt[:Line2D]((0,1),(0,0), color=pyfillcolor(series.d), linewidth=4)
else
series.d[:serieshandle][1]

View File

@ -44,7 +44,7 @@ supportedArgs(::QwtBackend) = [
:xscale,
:yscale,
]
supportedTypes(::QwtBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :hist2d, :hexbin, :hist, :bar, :hline, :vline]
supportedTypes(::QwtBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :histogram2d, :hexbin, :histogram, :bar, :hline, :vline]
supportedMarkers(::QwtBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon]
supportedScales(::QwtBackend) = [:identity, :log10]
subplotSupported(::QwtBackend) = true
@ -109,7 +109,7 @@ function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...)
elseif !iscreating && st == :bar
d = barHack(; kw...)
elseif !iscreating && st == :hist
elseif !iscreating && st == :histogram
d = barHack(; histogramHack(; kw...)...)
end

View File

@ -54,7 +54,7 @@ supportedArgs(::UnicodePlotsBackend) = [
supportedAxes(::UnicodePlotsBackend) = [:auto, :left]
supportedTypes(::UnicodePlotsBackend) = [
:path, :steppre, :steppost, :scatter,
:hist2d, :hline, :vline
:histogram2d, :hline, :vline
]
supportedStyles(::UnicodePlotsBackend) = [:auto, :solid]
supportedMarkers(::UnicodePlotsBackend) = [:none, :auto, :ellipse]
@ -197,11 +197,11 @@ function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
# UnicodePlots.barplot!(o, d[:x], d[:y])
# return
# elseif st == :hist
# elseif st == :histogram
# UnicodePlots.histogram!(o, d[:y], bins = d[:bins])
# return
elseif st == :hist2d
elseif st == :histogram2d
UnicodePlots.densityplot!(o, d[:x], d[:y])
return
@ -260,7 +260,7 @@ end
# # TODO don't need these once the "bar" series recipe is done
# if d[:seriestype] in (:sticks, :bar)
# d = barHack(; d...)
# elseif d[:seriestype] == :hist
# elseif d[:seriestype] == :histogram
# d = barHack(; histogramHack(; d...)...)
# end
# # push!(plt.seriesargs, d)

View File

@ -56,7 +56,7 @@ supportedArgs(::WinstonBackend) = [
# :z,
]
supportedAxes(::WinstonBackend) = [:auto, :left]
supportedTypes(::WinstonBackend) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedTypes(::WinstonBackend) = [:none, :line, :path, :sticks, :scatter, :histogram, :bar]
supportedStyles(::WinstonBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::WinstonBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5]
supportedScales(::WinstonBackend) = [:identity, :log10]
@ -150,7 +150,7 @@ function _series_added(plt::Plot{WinstonBackend}, series::Series)
## lintype :path, :step, :stepinverted, :sticks, :dots, :none, :hist2d, :hexbin, :hist, :bar
## lintype :path, :step, :stepinverted, :sticks, :dots, :none, :histogram2d, :hexbin, :histogram, :bar
if d[:seriestype] == :none
Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)..., color=getColor(d[:markercolor])))
@ -185,13 +185,13 @@ function _series_added(plt::Plot{WinstonBackend}, series::Series)
# elseif d[:seriestype] == :dots
# fn = Winston.XXX
# elseif d[:seriestype] == :hist2d
# elseif d[:seriestype] == :histogram2d
# fn = Winston.XXX
# elseif d[:seriestype] == :hexbin
# fn = Winston.XXX
elseif d[:seriestype] == :hist
elseif d[:seriestype] == :histogram
hst = hist(d[:y], d[:bins])
Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :bins)...))
@ -211,7 +211,7 @@ function _series_added(plt::Plot{WinstonBackend}, series::Series)
# optionally add a regression line
d[:smooth] && d[:seriestype] != :hist && addRegressionLineWinston(d, wplt)
d[:smooth] && d[:seriestype] != :histogram && addRegressionLineWinston(d, wplt)
# push!(plt.seriesargs, d)
# plt

View File

@ -233,8 +233,8 @@ function recompute_lengths(v)
end
end
leftover = 1.0pct - tot
if leftover.value <= 0
error("Not enough length left over in layout! v = $v, leftover = $leftover")
if cnt > 1 && leftover.value <= 0
error("Not enough length left over in layout! v = $v, cnt = $cnt, leftover = $leftover")
end
# now fill in the blanks

View File

@ -396,7 +396,7 @@ end
# error("gr_barplot: x must be same length as y (centers), or one more than y (edges).\n\t\tlength(x)=$(length(x)), length(y)=$(length(y))")
# end
@recipe function f(::Type{Val{:hist}}, x, y, z)
@recipe function f(::Type{Val{:histogram}}, x, y, z)
edges, counts = Base.hist(y, d[:bins])
d[:x] = edges
d[:y] = counts

View File

@ -37,7 +37,7 @@ series_list(sp::Subplot) = filter(series -> series.d[:subplot] === sp, sp.plt.se
function should_add_to_legend(series::Series)
!(series.d[:label] == "" || series.d[:seriestype] in (
:hexbin,:hist2d,:hline,:vline,
:hexbin,:histogram2d,:hline,:vline,
:contour,:contour3d,:surface,:wireframe,
:heatmap,:path3d,:scatter3d, :pie, :image
))

View File

@ -336,7 +336,7 @@ allFunctions(arg) = trueOrAllTrue(a -> isa(a, Function), arg)
"""
Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example:
```
with(:gadfly, size=(400,400), type=:hist) do
with(:gadfly, size=(400,400), type=:histogram) do
plot(rand(10))
plot(rand(10))
end

View File

@ -73,10 +73,10 @@ end
facts("Axes") do
axis = xaxis()
@fact typeof(axis) --> Axis
@fact Plots.discrete_value!(axis, "HI") --> 0.5
@fact Plots.discrete_value!(axis, :yo) --> 1.5
@fact Plots.discrete_value!(axis, "HI") --> (0.5, 1)
@fact Plots.discrete_value!(axis, :yo) --> (1.5, 2)
@fact extrema(axis) --> (0.5,1.5)
@fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 1.5, "HI" => 0.5)
@fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 2, "HI" => 1)
Plots.discrete_value!(axis, ["x$i" for i=1:5])
Plots.discrete_value!(axis, ["x$i" for i=0:2])