plotly zaxis, tick rotation, 3d axis fix; dataframes recipe fixes

This commit is contained in:
Thomas Breloff 2016-05-09 11:19:20 -04:00
parent c563204b0a
commit fdb01046e6
4 changed files with 62 additions and 67 deletions

View File

@ -50,6 +50,8 @@ like_histogram(linetype::Symbol) = linetype in (:hist, :density)
like_line(linetype::Symbol) = linetype in (:line, :path, :steppre, :steppost) like_line(linetype::Symbol) = linetype in (:line, :path, :steppre, :steppost)
like_surface(linetype::Symbol) = linetype in (:contour, :contour3d, :heatmap, :surface, :wireframe, :image) 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] const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
@compat const _styleAliases = KW( @compat const _styleAliases = KW(
@ -649,7 +651,7 @@ function extractGroupArgs(v::AVec, args...)
groupLabels = sort(collect(unique(v))) groupLabels = sort(collect(unique(v)))
n = length(groupLabels) n = length(groupLabels)
if n > 20 if n > 20
error("Too many group labels. n=$n Is that intended?") warn("You created n=$n groups... Is that intended?")
end end
groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels] groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels]
GroupBy(map(string, groupLabels), groupIds) GroupBy(map(string, groupLabels), groupIds)

View File

@ -3,67 +3,37 @@
supportedArgs(::PlotlyBackend) = [ supportedArgs(::PlotlyBackend) = [
:annotation, :annotation,
# :axis, :background_color, :foreground_color, :color_palette,
:background_color, # :background_color_legend, :background_color_inside, :background_color_outside,
:color_palette, # :foreground_color_legend, :foreground_color_grid, :foreground_color_axis,
:fillrange, # :foreground_color_text, :foreground_color_border,
:fillcolor,
:fillalpha,
:foreground_color,
:group, :group,
:label, :label,
:layout,
:legend,
:seriescolor, :seriesalpha,
:linecolor,
:linestyle,
:linetype, :linetype,
:linewidth, :seriescolor, :seriesalpha,
:linealpha, :linecolor, :linestyle, :linewidth, :linealpha,
:markershape, :markershape, :markercolor, :markersize, :markeralpha,
:markercolor, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
:markersize, :fillrange, :fillcolor, :fillalpha,
:markeralpha,
:markerstrokewidth,
:markerstrokecolor,
:markerstrokestyle,
:n,
:bins, :bins,
:nc, :n, :nc, :nr, :layout,
:nr,
# :pos,
# :smooth, # :smooth,
:show, :title, :windowtitle, :show, :size,
:size, :x, :xlabel, :xlims, :xticks, :xscale, :xflip, :xrotation,
:title, :y, :ylabel, :ylims, :yticks, :yscale, :yflip, :yrotation,
:windowtitle, :z, :zlabel, :zlims, :zticks, :zscale, :zflip, :zrotation,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
:yticks,
:xscale,
:yscale,
:xflip,
:yflip,
:z, :z,
:marker_z, :tickfont, :guidefont, :legendfont,
:tickfont, :grid, :legend, :colorbar,
:guidefont, :marker_z, :levels,
:legendfont, :xerror, :yerror,
:grid, :ribbon, :quiver,
:levels,
:xerror,
:yerror,
:ribbon,
:quiver,
:orientation, :orientation,
# :overwrite_figure,
:polar, :polar,
# :normalize, :weights, :contours, :aspect_ratio
] ]
supportedAxes(::PlotlyBackend) = [:auto, :left] supportedAxes(::PlotlyBackend) = [:auto, :left]
supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost, supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost,
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d, :hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
@ -229,37 +199,43 @@ end
use_axis_field(ticks) = !(ticks in (nothing, :none)) use_axis_field(ticks) = !(ticks in (nothing, :none))
tickssym(isx::Bool) = symbol((isx ? "x" : "y") * "ticks") tickssym(letter) = symbol(letter * "ticks")
limssym(isx::Bool) = symbol((isx ? "x" : "y") * "lims") limssym(letter) = symbol(letter * "lims")
flipsym(isx::Bool) = symbol((isx ? "x" : "y") * "flip") flipsym(letter) = symbol(letter * "flip")
scalesym(isx::Bool) = symbol((isx ? "x" : "y") * "scale") scalesym(letter) = symbol(letter * "scale")
labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label") labelsym(letter) = symbol(letter * "label")
rotationsym(letter) = symbol(letter * "rotation")
function plotlyaxis(d::KW, isx::Bool) function plotlyaxis(d::KW, letter)
ax = KW( ax = KW(
:title => d[labelsym(isx)], :title => d[labelsym(letter)],
:showgrid => d[:grid], :showgrid => d[:grid],
:zeroline => false, :zeroline => false,
) )
fgcolor = webcolor(d[:foreground_color]) 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]) if use_axis_field(d[tsym])
ax[:titlefont] = plotlyfont(d[:guidefont], fgcolor) 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[:tickfont] = plotlyfont(d[:tickfont], fgcolor)
ax[:tickcolor] = fgcolor ax[:tickcolor] = fgcolor
ax[:linecolor] = fgcolor ax[:linecolor] = fgcolor
# xlims # xlims
lims = d[limssym(isx)] lims = d[limssym(letter)]
if lims != :auto && limsType(lims) == :limits if lims != :auto && limsType(lims) == :limits
ax[:range] = lims ax[:range] = lims
end end
# xflip # xflip
if d[flipsym(isx)] if d[flipsym(letter)]
ax[:autorange] = "reversed" ax[:autorange] = "reversed"
end end
@ -303,8 +279,16 @@ function plotly_layout(d::KW)
d_out[:paper_bgcolor] = bgcolor d_out[:paper_bgcolor] = bgcolor
# TODO: x/y axis tick values/labels # TODO: x/y axis tick values/labels
d_out[:xaxis] = plotlyaxis(d, true) if is3d(d)
d_out[:yaxis] = plotlyaxis(d, false) 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 # legend
d_out[:showlegend] = d[:legend] != :none d_out[:showlegend] = d[:legend] != :none

View File

@ -173,6 +173,7 @@ function _add_series(plt::Plot, d::KW, ::Void, args...;
# filter the data # filter the data
filter_data!(d, idxfilter) filter_data!(d, idxfilter)
end end
# dumpdict(d,"",true)
seriesArgList, xmeta, ymeta = build_series_args(plt, d) #, idxfilter) seriesArgList, xmeta, ymeta = build_series_args(plt, d) #, idxfilter)
# seriesArgList, xmeta, ymeta = build_series_args(plt, groupargs..., args...; d...) # seriesArgList, xmeta, ymeta = build_series_args(plt, groupargs..., args...; d...)

View File

@ -462,7 +462,7 @@ function setup_dataframes()
# @eval begin # @eval begin
# import DataFrames # import DataFrames
DFS = Union{Symbol, AbstractVector{Symbol}} DFS = Union{Symbol, AbstractArray{Symbol}}
function handle_dfs(df::DataFrames.AbstractDataFrame, d::KW, letter, dfs::DFS) function handle_dfs(df::DataFrames.AbstractDataFrame, d::KW, letter, dfs::DFS)
if isa(dfs, Symbol) if isa(dfs, Symbol)
@ -495,6 +495,14 @@ function setup_dataframes()
x, y x, y
end 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::Symbol) = df[arg]
# get_data(df::DataFrames.AbstractDataFrame, arg) = arg # get_data(df::DataFrames.AbstractDataFrame, arg) = arg
# #