From ef7370f56dcea5968664160538986e3ba493d9dc Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Sat, 21 Nov 2015 09:26:35 -0500 Subject: [PATCH] added density type --- src/Plots.jl | 8 ++++++-- src/args.jl | 19 ++++++++++++------- src/backends/pyplot.jl | 10 ++++++---- src/backends/supported.jl | 8 ++++++-- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e0360b49..f6986786 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -35,6 +35,8 @@ export bar!, histogram, histogram!, + density, + density!, heatmap, heatmap!, hexbin, @@ -135,10 +137,12 @@ bar(args...; kw...) = plot(args...; kw..., linetype = :bar) bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar) histogram(args...; kw...) = plot(args...; kw..., linetype = :hist) histogram!(args...; kw...) = plot!(args...; kw..., linetype = :hist) +density(args...; kw...) = plot(args...; kw..., linetype = :density) +density!(args...; kw...) = plot!(args...; kw..., linetype = :density) heatmap(args...; kw...) = plot(args...; kw..., linetype = :heatmap) heatmap!(args...; kw...) = plot!(args...; kw..., linetype = :heatmap) -hexbin(args...; kw...) = plot(args...; kw..., linetype = :hexbin) -hexbin!(args...; kw...) = plot!(args...; kw..., linetype = :hexbin) +hexbin(args...; kw...) = plot(args...; kw..., linetype = :hexbin) +hexbin!(args...; kw...) = plot!(args...; kw..., linetype = :hexbin) sticks(args...; kw...) = plot(args...; kw..., linetype = :sticks, marker = :ellipse) sticks!(args...; kw...) = plot!(args...; kw..., linetype = :sticks, marker = :ellipse) hline(args...; kw...) = plot(args...; kw..., linetype = :hline) diff --git a/src/args.jl b/src/args.jl index ac5bcb0f..ae65ff3f 100644 --- a/src/args.jl +++ b/src/args.jl @@ -10,7 +10,7 @@ const _allAxes = [:auto, :left, :right] const _3dTypes = [:path3d, :scatter3d] const _allTypes = vcat([ :none, :line, :path, :steppre, :steppost, :sticks, :scatter, - :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc, :contour + :heatmap, :hexbin, :hist, :density, :bar, :hline, :vline, :ohlc, :contour ], _3dTypes) @compat const _typeAliases = Dict( :n => :none, @@ -29,10 +29,15 @@ const _allTypes = vcat([ :stems => :sticks, :dots => :scatter, :histogram => :hist, + :pdf => :density, :contours => :contours, :line3d => :path3d, ) +ishistlike(lt::Symbol) = lt in (:hist, :density) +islinelike(lt::Symbol) = lt in (:line, :path, :steppre, :steppost) +isheatmaplike(lt::Symbol) = lt in (:heatmap, :hexbin) + const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @compat const _styleAliases = Dict( @@ -91,12 +96,12 @@ const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt] :ln => :log, ) -supportedAxes(::PlottingPackage) = _allAxes -supportedTypes(::PlottingPackage) = _allTypes -supportedStyles(::PlottingPackage) = _allStyles -supportedMarkers(::PlottingPackage) = _allMarkers -supportedScales(::PlottingPackage) = _allScales -subplotSupported(::PlottingPackage) = true +supportedAxes(::PlottingPackage) = [:left] +supportedTypes(::PlottingPackage) = [] +supportedStyles(::PlottingPackage) = [:solid] +supportedMarkers(::PlottingPackage) = [:none] +supportedScales(::PlottingPackage) = [:identity] +subplotSupported(::PlottingPackage) = false supportedAxes() = supportedAxes(backend()) supportedTypes() = supportedTypes(backend()) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index b9dbfaa2..1c07f787 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -126,6 +126,7 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol) # ax[:set_ylabel](plt.plotargs[:yrightlabel]) fmap = @compat Dict( :hist => :hist, + :density => :hist, :sticks => :bar, :bar => :bar, :heatmap => :hexbin, @@ -246,13 +247,14 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...) plotfunc = getPyPlotFunction(plt, d[:axis], lt) # we have different args depending on plot type - if lt in (:hist, :sticks, :bar) + if lt in (:hist, :density, :sticks, :bar) # NOTE: this is unsupported because it does the wrong thing... it shifts the whole axis # extra_kwargs[:bottom] = d[:fill] - if lt == :hist + if ishistlike(lt) extra_kwargs[:bins] = d[:nbins] + extra_kwargs[:normed] = lt == :density else extra_kwargs[:linewidth] = (lt == :sticks ? 0.1 : 0.9) end @@ -312,7 +314,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...) end # do the plot - d[:serieshandle] = if lt == :hist + d[:serieshandle] = if ishistlike(lt) plotfunc(d[:y]; extra_kwargs...)[1] elseif lt == :contour # NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed), @@ -607,7 +609,7 @@ end function addPyPlotLegend(plt::Plot, ax) if plt.plotargs[:legend] # gotta do this to ensure both axes are included - args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap,:hline,:vline,:contour, :path3d, :scatter3d)), plt.seriesargs) + args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:heatmap,:hline,:vline,:contour, :path3d, :scatter3d)), plt.seriesargs) if length(args) > 0 leg = ax[:legend]([d[:serieshandle] for d in args], [d[:label] for d in args], diff --git a/src/backends/supported.jl b/src/backends/supported.jl index 45af2247..f2b78f70 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -57,7 +57,9 @@ supportedArgs(::GadflyPackage) = [ :nlevels, ] supportedAxes(::GadflyPackage) = [:auto, :left] -supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] +supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, + :scatter, :heatmap, :hexbin, :hist, :bar, + :hline, :vline, :contour] supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape) supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt] @@ -136,7 +138,9 @@ supportedArgs(::PyPlotPackage) = [ :markeralpha, ] supportedAxes(::PyPlotPackage) = _allAxes -supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour, :path3d, :scatter3d] +supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, + :scatter, :heatmap, :hexbin, :hist, :density, :bar, + :hline, :vline, :contour, :path3d, :scatter3d] supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot] # supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon] supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)