Compare commits

..

1 Commits

Author SHA1 Message Date
Michael K. Borregaard 233f4d4465 make linspace arg a float 2017-08-30 15:04:03 +02:00
14 changed files with 56 additions and 63 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ const _arg_desc = KW(
:markerstrokewidth => "Number. Width of the marker stroke (border. in pixels)",
:markerstrokecolor => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.",
:markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.",
:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `linspace(extrema(x)..., 25)`",
:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto. For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `linspace(extrema(x)..., 25)`",
:smooth => "Bool. Add a regression line?",
:group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`.",
:x => "Various. Input data. First Dimension",
@@ -40,7 +40,7 @@ const _arg_desc = KW(
:ribbon => "Number or AbstractVector. Creates a fillrange around the data points.",
:quiver => "AbstractVector or 2-Tuple of vectors. The directional vectors U,V which specify velocity/gradient vectors for a quiver plot.",
:arrow => "nothing (no arrows), Bool (if true, default arrows), Arrow object, or arg(s) that could be style or head length/widths. Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar.",
:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a discrete Probability Density Function, where the total area of the bins is 1), :probability (bin heights sum to 1) and :density (the area of each bin, rather than the height, is equal to the counts - useful for uneven bin sizes).",
:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a PDF with integral of 1) and :density (only normalize in respect to bin sizes).",
:weights => "AbstractVector. Used in histogram types for weighted counts.",
:contours => "Bool. Add contours to the side-grids of 3D plots? Used in surface/wireframe.",
:match_dimensions => "Bool. For heatmap types... should the first dimension of a matrix (rows) correspond to the first dimension of the plot (x-axis)? The default is false, which matches the behavior of Matplotlib, Plotly, and others. Note: when passing a function for z, the function should still map `(x,y) -> z`.",
+6 -11
View File
@@ -80,13 +80,9 @@ const _typeAliases = Dict{Symbol,Symbol}(
add_non_underscore_aliases!(_typeAliases)
const _histogram_like = [:histogram, :barhist, :barbins]
const _line_like = [:line, :path, :steppre, :steppost]
const _surface_like = [:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image]
like_histogram(seriestype::Symbol) = seriestype in _histogram_like
like_line(seriestype::Symbol) = seriestype in _line_like
like_surface(seriestype::Symbol) = seriestype in _surface_like
like_histogram(seriestype::Symbol) = seriestype in (:histogram, :barhist, :barbins)
like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost)
like_surface(seriestype::Symbol) = seriestype in (:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image)
is3d(seriestype::Symbol) = seriestype in _3dTypes
is3d(series::Series) = is3d(series.d)
@@ -866,7 +862,7 @@ function extractGroupArgs(v::AVec, args...; legendEntry = string)
if n > 100
warn("You created n=$n groups... Is that intended?")
end
groupIds = Vector{Int}[filter(i -> v[i] == glab, linearindices(v)) for glab in groupLabels]
groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels]
GroupBy(map(legendEntry, groupLabels), groupIds)
end
@@ -874,7 +870,7 @@ legendEntryFromTuple(ns::Tuple) = string(("$n " for n in ns)...)
# this is when given a tuple of vectors of values to group by
function extractGroupArgs(vs::Tuple, args...)
(vs == ()) && return GroupBy([""], [indices(args[1],1)])
(vs == ()) && return GroupBy([""], [1:size(args[1],1)])
v = collect(zip(vs...))
extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple)
end
@@ -983,8 +979,7 @@ convertLegendValue(v::AbstractArray) = map(convertLegendValue, v)
# anything else is returned as-is
function slice_arg(v::AMat, idx::Int)
c = mod1(idx, size(v,2))
m,n = indices(v)
size(v,1) == 1 ? v[first(m),n[c]] : v[:,n[c]]
size(v,1) == 1 ? v[1,c] : v[:,c]
end
slice_arg(wrapper::InputWrapper, idx) = wrapper.obj
slice_arg(v, idx) = v
+8 -8
View File
@@ -461,10 +461,10 @@ end
# add the discrete value for each item. return the continuous values and the indices
function discrete_value!(axis::Axis, v::AVec)
n = linearindices(v)
cvec = zeros(length(n))
discrete_indices = zeros(Int, length(n))
for i=n
n = length(v)
cvec = zeros(n)
discrete_indices = zeros(Int, n)
for i=1:n
cvec[i], discrete_indices[i] = discrete_value!(axis, v[i])
end
cvec, discrete_indices
@@ -472,10 +472,10 @@ end
# add the discrete value for each item. return the continuous values and the indices
function discrete_value!(axis::Axis, v::AMat)
n,m = indices(v)
cmat = zeros(v)
discrete_indices = similar(Array{Int}, n, m)
@inbounds for i=n, j=m
n,m = size(v)
cmat = zeros(n,m)
discrete_indices = zeros(Int, n, m)
for i=1:n, j=1:m
cmat[i,j], discrete_indices[i,j] = discrete_value!(axis, v[i,j])
end
cmat, discrete_indices
+10 -10
View File
@@ -784,7 +784,7 @@ end
function gl_bar(d, kw_args)
x, y = d[:x], d[:y]
nx, ny = length(linearindices(x)), length(linearindices(y))
nx, ny = length(x), length(y)
axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
cv = [discrete_value!(axis, xi)[1] for xi=x]
x = if nx == ny
@@ -792,7 +792,7 @@ function gl_bar(d, kw_args)
elseif nx == ny + 1
0.5diff(cv) + cv[1:end-1]
else
error("bar recipe: x must be same length as y (centers), or one more than y (edges).\n\t\tlength(x)=$(nx), length(y)=$(ny)")
error("bar recipe: 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
if haskey(kw_args, :stroke_width) # stroke is inside for bars
#kw_args[:stroke_width] = -kw_args[:stroke_width]
@@ -802,7 +802,7 @@ function gl_bar(d, kw_args)
hw = if bw == nothing
ignorenan_mean(diff(x))
else
Float64[_cycle(bw,i)*0.5 for i=linearindices(x)]
Float64[_cycle(bw,i)*0.5 for i=1:length(x)]
end
# make fillto a vector... default fills to 0
@@ -852,11 +852,11 @@ function gl_boxplot(d, kw_args)
sx, sy = m[1,1], m[2,2]
for (i,glabel) in enumerate(glabels)
# filter y
values = y[filter(i -> _cycle(x,i) == glabel, linearindices(y))]
values = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))]
# compute quantiles
q1,q2,q3,q4,q5 = quantile(values, linspace(0,1,5))
# notch
n = Plots.notch_width(q2, q4, length(linearindices(values)))
n = Plots.notch_width(q2, q4, length(values))
# warn on inverted notches?
if notch && !warning && ( (q2>(q3-n)) || (q4<(q3+n)) )
warn("Boxplot's notch went outside hinges. Set notch to false.")
@@ -963,7 +963,7 @@ function scale_for_annotations!(series::Series, scaletype::Symbol = :pixels)
# with a list of custom shapes for each
msw, msh = anns.scalefactor
offsets = Array{Vec2f0}(length(anns.strs))
series[:markersize] = map(linearindices(anns.strs)) do i
series[:markersize] = map(1:length(anns.strs)) do i
str = _cycle(anns.strs, i)
# get the width and height of the string (in mm)
sw, sh = text_size(str, anns.font.pointsize)
@@ -1077,7 +1077,7 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
kw = copy(kw_args)
fr = d[:fillrange]
ps = if all(x-> x >= 0, diff(d[:x])) # if is monotonic
vcat(points, Point2f0[(points[i][1], _cycle(fr, i)) for i=reverse(linearindices(points))])
vcat(points, Point2f0[(points[i][1], _cycle(fr, i)) for i=length(points):-1:1])
else
points
end
@@ -1291,8 +1291,8 @@ function gl_surface(x,y,z, kw_args)
if isa(x, AbstractMatrix) && isa(y, AbstractMatrix)
main = map(s->map(Float32, s), (x, y, z))
elseif isa(x, AbstractVector) || isa(y, AbstractVector)
x = Float32[x[i] for i = indices(z,1), j = indices(z,2)]
y = Float32[y[j] for i = indices(z,1), j = indices(z,2)]
x = Float32[x[i] for i = 1:size(z,1), j = 1:size(z,2)]
y = Float32[y[j] for i = 1:size(z,1), j = 1:size(z,2)]
main = (x, y, map(Float32, z))
else
error("surface: combination of types not supported: $(typeof(x)) $(typeof(y)) $(typeof(z))")
@@ -1301,7 +1301,7 @@ function gl_surface(x,y,z, kw_args)
points = map(Point3f0, zip(vec(x), vec(y), vec(z)))
faces = Cuint[]
idx = (i,j) -> sub2ind(size(z), i, j) - 1
for i=indices(z,1), j=indices(z,2)
for i=1:size(z,1), j=1:size(z,2)
i < size(z,1) && push!(faces, idx(i, j), idx(i+1, j))
j < size(z,2) && push!(faces, idx(i, j), idx(i, j+1))
+1 -1
View File
@@ -306,7 +306,7 @@ end
function gr_draw_markers(series::Series, x, y, msize, mz)
shapes = series[:markershape]
if shapes != :none
for i=linearindices(x)
for i=1:length(x)
msi = _cycle(msize, i)
shape = _cycle(shapes, i)
cfunc = isa(shape, Shape) ? gr_set_fillcolor : gr_set_markercolor
+2 -2
View File
@@ -370,7 +370,7 @@ end
function plotly_colorscale(grad::ColorGradient, α)
[[grad.values[i], rgb_string(grad.colors[i])] for i in linearindices(grad.colors)]
[[grad.values[i], rgb_string(grad.colors[i])] for i in 1:length(grad.colors)]
end
plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α)
# plotly_colorscale(c, alpha = nothing) = plotly_colorscale(cgrad(), alpha)
@@ -397,7 +397,7 @@ end
# we split by NaNs and then construct/destruct the shapes to get the closed coords
function plotly_close_shapes(x, y)
xs, ys = nansplit(x), nansplit(y)
for i=linearindices(xs)
for i=1:length(xs)
shape = Shape(xs[i], ys[i])
xs[i], ys[i] = coords(shape)
end
+3 -3
View File
@@ -244,7 +244,7 @@ end
# end
function get_locator_and_formatter(vals::AVec)
pyticker["FixedLocator"](linearindices(vals)), pyticker["FixedFormatter"](vals)
pyticker["FixedLocator"](1:length(vals)), pyticker["FixedFormatter"](vals)
end
function add_pyfixedformatter(cbar, vals::AVec)
@@ -589,7 +589,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
shapes = series[:markershape]
msc = py_markerstrokecolor(series)
lw = py_dpi_scale(plt, series[:markerstrokewidth])
for i=linearindices(y)
for i=1:length(y)
extrakw[:c] = if series[:marker_z] == nothing
py_color_fix(py_color(_cycle(series[:markercolor],i)), x)
else
@@ -850,7 +850,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
kw = KW()
if discrete_colorbar_values != nothing
locator, formatter = get_locator_and_formatter(discrete_colorbar_values)
# kw[:values] = linearindices(discrete_colorbar_values)
# kw[:values] = 1:length(discrete_colorbar_values)
kw[:values] = sp[:zaxis][:continuous_values]
kw[:ticks] = locator
kw[:format] = formatter
+5 -5
View File
@@ -89,7 +89,7 @@ end
"create a shape by picking points around the unit circle. `n` is the number of point/sides, `offset` is the starting angle"
function makeshape(n; offset = -0.5, radius = 1.0)
z = offset * π
Shape(partialcircle(z, z + 2π, n+1, radius))
Shape(partialcircle(z, z + 2π, n+1., radius))
end
@@ -186,7 +186,7 @@ end
function scale!(shape::Shape, x::Real, y::Real = x, c = center(shape))
sx, sy = coords(shape)
cx, cy = c
for i=linearindices(sx)
for i=1:length(sx)
sx[i] = (sx[i] - cx) * x + cx
sy[i] = (sy[i] - cy) * y + cy
end
@@ -201,7 +201,7 @@ end
"translate a Shape in space"
function translate!(shape::Shape, x::Real, y::Real = x)
sx, sy = coords(shape)
for i=linearindices(sx)
for i=1:length(sx)
sx[i] += x
sy[i] += y
end
@@ -229,7 +229,7 @@ end
function rotate!(shape::Shape, Θ::Real, c = center(shape))
x, y = coords(shape)
cx, cy = c
for i=linearindices(x)
for i=1:length(x)
xi = rotate_x(x[i], y[i], Θ, cx, cy)
yi = rotate_y(x[i], y[i], Θ, cx, cy)
x[i], y[i] = xi, yi
@@ -506,7 +506,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
push!(msize, maxscale)
baseshape = _cycle(get(anns.baseshape),i)
shape = scale(baseshape, msw*xscale/maxscale, msh*yscale/maxscale, (0,0))
end for i=linearindices(anns.strs)]
end for i=1:length(anns.strs)]
series[:markershape] = shapes
series[:markersize] = msize
end
+3 -3
View File
@@ -258,7 +258,7 @@ function addToGadflyLegend(plt::Plot, d::KW)
foundit = false
# extend the label if we found this color
for i in linearindices(guide.colors)
for i in 1:length(guide.colors)
if RGB(c) == guide.colors[i]
guide.labels[i] *= ", " * d[:label]
foundit = true
@@ -333,9 +333,9 @@ end
# # this is super weird, but... oh well... for some reason this creates n separate line segments...
# # create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y)
# # then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n]
# csindices = Int[mod1(i,length(cscheme.v)) for i in linearindices(d[:y])]
# csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(d[:y])]
# cs = collect(repmat(csindices', 2, 1))[1:end-1]
# grp = collect(repmat((linearindices(d[:y]))', 2, 1))[1:end-1]
# grp = collect(repmat((1:length(d[:y]))', 2, 1))[1:end-1]
# d[:x], d[:y] = map(createSegments, (d[:x], d[:y]))
# colorgroup = [(:linecolor, cs), (:group, grp)]
+2 -2
View File
@@ -290,7 +290,7 @@ PlotExample("Layouts, margins, label rotation, title location",
[:(begin
plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"],
title_location=:left, left_margin=[20mm 0mm],
bottom_margin=10px, xrotation=60)
bottom_margin=50px, xrotation=60)
end)]
),
@@ -379,7 +379,7 @@ function test_examples(pkgname::Symbol; debug = false, disp = true, sleep = noth
skip = [], only = nothing)
Plots._debugMode.on = debug
plts = Dict()
for i in linearindices(_examples)
for i in 1:length(_examples)
only != nothing && !(i in only) && continue
i in skip && continue
try
+5 -7
View File
@@ -291,7 +291,7 @@ end
hw = if bw == nothing
0.5ignorenan_mean(diff(procx))
else
Float64[0.5_cycle(bw,i) for i=linearindices(procx)]
Float64[0.5_cycle(bw,i) for i=1:length(procx)]
end
# make fillto a vector... default fills to 0
@@ -510,10 +510,8 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode
v = vs[dim]
if mode == :auto
mode = :fd
end
if mode == :sqrt # Square-root choice
30
elseif mode == :sqrt # Square-root choice
_cl(sqrt(n))
elseif mode == :sturges # Sturges' formula
_cl(log2(n)) + 1
@@ -552,7 +550,7 @@ end
@recipe function f(::Type{Val{:histogram}}, x, y, z)
seriestype := length(y) > 1e6 ? :stephist : :barhist
seriestype := :barhist
()
end
@deps histogram barhist
@@ -872,7 +870,7 @@ function get_xy(o::OHLC, x, xdiff)
end
# get the joined vector
function get_xy(v::AVec{OHLC}, x = linearindices(v))
function get_xy(v::AVec{OHLC}, x = 1:length(v))
xdiff = 0.3ignorenan_mean(abs.(diff(x)))
x_out, y_out = zeros(0), zeros(0)
for (i,ohlc) in enumerate(v)
+5 -5
View File
@@ -69,13 +69,13 @@ end
# TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array
# result in that array being shared. push!, etc will add too many items to that array
compute_x(x::Void, y::Void, z) = indices(z,1)
compute_x(x::Void, y, z) = indices(y,1)
compute_x(x::Void, y::Void, z) = 1:size(z,1)
compute_x(x::Void, y, z) = 1:size(y,1)
compute_x(x::Function, y, z) = map(x, y)
compute_x(x, y, z) = copy(x)
# compute_y(x::Void, y::Function, z) = error()
compute_y(x::Void, y::Void, z) = indices(z,2)
compute_y(x::Void, y::Void, z) = 1:size(z,2)
compute_y(x, y::Function, z) = map(y, x)
compute_y(x, y, z) = copy(y)
@@ -272,9 +272,9 @@ end
# return a surface if this is a 3d plot, otherwise let it be sliced up
@recipe function f{T<:Union{Integer,AbstractFloat}}(mat::AMat{T})
if all3D(d)
inds = indices(mat)
n,m = size(mat)
wrap_surfaces(d)
SliceIt, inds[2], inds[1], Surface(mat)
SliceIt, 1:m, 1:n, Surface(mat)
else
SliceIt, nothing, mat, nothing
end
+3 -3
View File
@@ -1,5 +1,5 @@
calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for i in linearindices(edges)-1]
calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for i in 1:length(edges)-1]
"Make histogram-like bins of data"
function binData(data, nbins)
@@ -43,7 +43,7 @@ function barHack(; kw...)
# estimate the edges
dists = diff(midpoints) * 0.5
edges = zeros(length(midpoints)+1)
for i in linearindices(edges)
for i in 1:length(edges)
if i == 1
edge = midpoints[1] - dists[1]
elseif i == length(edges)
@@ -56,7 +56,7 @@ function barHack(; kw...)
x = Float64[]
y = Float64[]
for i in linearindices(heights)
for i in 1:length(heights)
e1, e2 = edges[i:i+1]
append!(x, [e1, e1, e2, e2])
append!(y, [fillrange, heights[i], heights[i], fillrange])
+1 -1
View File
@@ -92,7 +92,7 @@ function image_comparison_facts(pkg::Symbol;
debug = false, # print debug information?
sigma = [1,1], # number of pixels to "blur"
eps = 1e-2) # acceptable error (percent)
for i in linearindices(Plots._examples)
for i in 1:length(Plots._examples)
i in skip && continue
if only == nothing || i in only
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true