From fdb01046e636f08f4f879883995072b78070d004 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 9 May 2016 11:19:20 -0400 Subject: [PATCH] plotly zaxis, tick rotation, 3d axis fix; dataframes recipe fixes --- src/args.jl | 4 +- src/backends/plotly.jl | 114 ++++++++++++++++++----------------------- src/plot.jl | 1 + src/series_args.jl | 10 +++- 4 files changed, 62 insertions(+), 67 deletions(-) diff --git a/src/args.jl b/src/args.jl index eb61b68e..0f63714a 100644 --- a/src/args.jl +++ b/src/args.jl @@ -50,6 +50,8 @@ like_histogram(linetype::Symbol) = linetype in (:hist, :density) like_line(linetype::Symbol) = linetype in (:line, :path, :steppre, :steppost) like_surface(linetype::Symbol) = linetype in (:contour, :contour3d, :heatmap, :surface, :wireframe, :image) +is3d(linetype::Symbol) = linetype in _3dTypes +is3d(d::KW) = trueOrAllTrue(is3d, d[:linetype]) const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @compat const _styleAliases = KW( @@ -649,7 +651,7 @@ function extractGroupArgs(v::AVec, args...) groupLabels = sort(collect(unique(v))) n = length(groupLabels) if n > 20 - error("Too many group labels. n=$n Is that intended?") + warn("You created n=$n groups... Is that intended?") end groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels] GroupBy(map(string, groupLabels), groupIds) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index d7a1527d..e91c3933 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -3,67 +3,37 @@ supportedArgs(::PlotlyBackend) = [ :annotation, - # :axis, - :background_color, - :color_palette, - :fillrange, - :fillcolor, - :fillalpha, - :foreground_color, + :background_color, :foreground_color, :color_palette, + # :background_color_legend, :background_color_inside, :background_color_outside, + # :foreground_color_legend, :foreground_color_grid, :foreground_color_axis, + # :foreground_color_text, :foreground_color_border, :group, :label, - :layout, - :legend, - :seriescolor, :seriesalpha, - :linecolor, - :linestyle, :linetype, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokestyle, - :n, + :seriescolor, :seriesalpha, + :linecolor, :linestyle, :linewidth, :linealpha, + :markershape, :markercolor, :markersize, :markeralpha, + :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, + :fillrange, :fillcolor, :fillalpha, :bins, - :nc, - :nr, - # :pos, + :n, :nc, :nr, :layout, # :smooth, - :show, - :size, - :title, - :windowtitle, - :x, - :xlabel, - :xlims, - :xticks, - :y, - :ylabel, - :ylims, - # :yrightlabel, - :yticks, - :xscale, - :yscale, - :xflip, - :yflip, + :title, :windowtitle, :show, :size, + :x, :xlabel, :xlims, :xticks, :xscale, :xflip, :xrotation, + :y, :ylabel, :ylims, :yticks, :yscale, :yflip, :yrotation, + :z, :zlabel, :zlims, :zticks, :zscale, :zflip, :zrotation, :z, - :marker_z, - :tickfont, - :guidefont, - :legendfont, - :grid, - :levels, - :xerror, - :yerror, - :ribbon, - :quiver, + :tickfont, :guidefont, :legendfont, + :grid, :legend, :colorbar, + :marker_z, :levels, + :xerror, :yerror, + :ribbon, :quiver, :orientation, + # :overwrite_figure, :polar, + # :normalize, :weights, :contours, :aspect_ratio ] + supportedAxes(::PlotlyBackend) = [:auto, :left] supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost, :hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d, @@ -229,37 +199,43 @@ end use_axis_field(ticks) = !(ticks in (nothing, :none)) -tickssym(isx::Bool) = symbol((isx ? "x" : "y") * "ticks") -limssym(isx::Bool) = symbol((isx ? "x" : "y") * "lims") -flipsym(isx::Bool) = symbol((isx ? "x" : "y") * "flip") -scalesym(isx::Bool) = symbol((isx ? "x" : "y") * "scale") -labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label") +tickssym(letter) = symbol(letter * "ticks") +limssym(letter) = symbol(letter * "lims") +flipsym(letter) = symbol(letter * "flip") +scalesym(letter) = symbol(letter * "scale") +labelsym(letter) = symbol(letter * "label") +rotationsym(letter) = symbol(letter * "rotation") -function plotlyaxis(d::KW, isx::Bool) +function plotlyaxis(d::KW, letter) ax = KW( - :title => d[labelsym(isx)], + :title => d[labelsym(letter)], :showgrid => d[:grid], :zeroline => false, ) fgcolor = webcolor(d[:foreground_color]) - tsym = tickssym(isx) + tsym = tickssym(letter) + + rot = d[rotationsym(letter)] + if rot != 0 + ax[:tickangle] = rot + end if use_axis_field(d[tsym]) ax[:titlefont] = plotlyfont(d[:guidefont], fgcolor) - ax[:type] = plotlyscale(d[scalesym(isx)]) + ax[:type] = plotlyscale(d[scalesym(letter)]) ax[:tickfont] = plotlyfont(d[:tickfont], fgcolor) ax[:tickcolor] = fgcolor ax[:linecolor] = fgcolor # xlims - lims = d[limssym(isx)] + lims = d[limssym(letter)] if lims != :auto && limsType(lims) == :limits ax[:range] = lims end # xflip - if d[flipsym(isx)] + if d[flipsym(letter)] ax[:autorange] = "reversed" end @@ -303,8 +279,16 @@ function plotly_layout(d::KW) d_out[:paper_bgcolor] = bgcolor # TODO: x/y axis tick values/labels - d_out[:xaxis] = plotlyaxis(d, true) - d_out[:yaxis] = plotlyaxis(d, false) + if is3d(d) + d_out[:scene] = KW( + :xaxis => plotlyaxis(d, "x"), + :yaxis => plotlyaxis(d, "y"), + :xzxis => plotlyaxis(d, "z"), + ) + else + d_out[:xaxis] = plotlyaxis(d, "x") + d_out[:yaxis] = plotlyaxis(d, "y") + end # legend d_out[:showlegend] = d[:legend] != :none diff --git a/src/plot.jl b/src/plot.jl index f3763213..5edfe647 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -173,6 +173,7 @@ function _add_series(plt::Plot, d::KW, ::Void, args...; # filter the data filter_data!(d, idxfilter) end + # dumpdict(d,"",true) seriesArgList, xmeta, ymeta = build_series_args(plt, d) #, idxfilter) # seriesArgList, xmeta, ymeta = build_series_args(plt, groupargs..., args...; d...) diff --git a/src/series_args.jl b/src/series_args.jl index 7494bc2b..87ed1888 100644 --- a/src/series_args.jl +++ b/src/series_args.jl @@ -462,7 +462,7 @@ function setup_dataframes() # @eval begin # import DataFrames - DFS = Union{Symbol, AbstractVector{Symbol}} + DFS = Union{Symbol, AbstractArray{Symbol}} function handle_dfs(df::DataFrames.AbstractDataFrame, d::KW, letter, dfs::DFS) if isa(dfs, Symbol) @@ -495,6 +495,14 @@ function setup_dataframes() x, y end + @recipe function plot(df::DataFrames.AbstractDataFrame, sx::DFS, sy::DFS, sz::DFS) + handle_group(df, d) + x = handle_dfs(df, d, "x", sx) + y = handle_dfs(df, d, "y", sy) + z = handle_dfs(df, d, "z", sz) + x, y, z + end + # get_data(df::DataFrames.AbstractDataFrame, arg::Symbol) = df[arg] # get_data(df::DataFrames.AbstractDataFrame, arg) = arg #