color fixes; pyplot shape iteration; KernelDensity in travis and warning; attribute accessors
This commit is contained in:
parent
4d99b37def
commit
e53ab85745
@ -5,12 +5,12 @@ module Plots
|
|||||||
|
|
||||||
using Compat
|
using Compat
|
||||||
using Reexport
|
using Reexport
|
||||||
@reexport using Colors
|
# @reexport using Colors
|
||||||
# using Requires
|
# using Requires
|
||||||
using FixedSizeArrays
|
using FixedSizeArrays
|
||||||
@reexport using RecipesBase
|
@reexport using RecipesBase
|
||||||
using Base.Meta
|
using Base.Meta
|
||||||
using PlotUtils
|
@reexport using PlotUtils
|
||||||
|
|
||||||
export
|
export
|
||||||
AbstractPlot,
|
AbstractPlot,
|
||||||
|
|||||||
35
src/args.jl
35
src/args.jl
@ -499,7 +499,7 @@ function handleColors!(d::KW, arg, csym::Symbol)
|
|||||||
d[csym] = :auto
|
d[csym] = :auto
|
||||||
else
|
else
|
||||||
# c = colorscheme(arg)
|
# c = colorscheme(arg)
|
||||||
c = plot_color(arg, nothing)
|
c = plot_color(arg)
|
||||||
d[csym] = c
|
d[csym] = c
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -520,13 +520,13 @@ function processLineArg(d::KW, arg)
|
|||||||
|
|
||||||
elseif typeof(arg) <: Stroke
|
elseif typeof(arg) <: Stroke
|
||||||
arg.width == nothing || (d[:linewidth] = arg.width)
|
arg.width == nothing || (d[:linewidth] = arg.width)
|
||||||
arg.color == nothing || (d[:linecolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
arg.color == nothing || (d[:linecolor] = arg.color == :auto ? :auto : plot_color(arg.color))
|
||||||
arg.alpha == nothing || (d[:linealpha] = arg.alpha)
|
arg.alpha == nothing || (d[:linealpha] = arg.alpha)
|
||||||
arg.style == nothing || (d[:linestyle] = arg.style)
|
arg.style == nothing || (d[:linestyle] = arg.style)
|
||||||
|
|
||||||
elseif typeof(arg) <: Brush
|
elseif typeof(arg) <: Brush
|
||||||
arg.size == nothing || (d[:fillrange] = arg.size)
|
arg.size == nothing || (d[:fillrange] = arg.size)
|
||||||
arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color))
|
||||||
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
||||||
|
|
||||||
elseif typeof(arg) <: Arrow || arg in (:arrow, :arrows)
|
elseif typeof(arg) <: Arrow || arg in (:arrow, :arrows)
|
||||||
@ -559,13 +559,13 @@ function processMarkerArg(d::KW, arg)
|
|||||||
|
|
||||||
elseif typeof(arg) <: Stroke
|
elseif typeof(arg) <: Stroke
|
||||||
arg.width == nothing || (d[:markerstrokewidth] = arg.width)
|
arg.width == nothing || (d[:markerstrokewidth] = arg.width)
|
||||||
arg.color == nothing || (d[:markerstrokecolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
arg.color == nothing || (d[:markerstrokecolor] = arg.color == :auto ? :auto : plot_color(arg.color))
|
||||||
arg.alpha == nothing || (d[:markerstrokealpha] = arg.alpha)
|
arg.alpha == nothing || (d[:markerstrokealpha] = arg.alpha)
|
||||||
arg.style == nothing || (d[:markerstrokestyle] = arg.style)
|
arg.style == nothing || (d[:markerstrokestyle] = arg.style)
|
||||||
|
|
||||||
elseif typeof(arg) <: Brush
|
elseif typeof(arg) <: Brush
|
||||||
arg.size == nothing || (d[:markersize] = arg.size)
|
arg.size == nothing || (d[:markersize] = arg.size)
|
||||||
arg.color == nothing || (d[:markercolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
arg.color == nothing || (d[:markercolor] = arg.color == :auto ? :auto : plot_color(arg.color))
|
||||||
arg.alpha == nothing || (d[:markeralpha] = arg.alpha)
|
arg.alpha == nothing || (d[:markeralpha] = arg.alpha)
|
||||||
|
|
||||||
# linealpha
|
# linealpha
|
||||||
@ -587,7 +587,7 @@ end
|
|||||||
function processFillArg(d::KW, arg)
|
function processFillArg(d::KW, arg)
|
||||||
if typeof(arg) <: Brush
|
if typeof(arg) <: Brush
|
||||||
arg.size == nothing || (d[:fillrange] = arg.size)
|
arg.size == nothing || (d[:fillrange] = arg.size)
|
||||||
arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color))
|
||||||
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
||||||
|
|
||||||
# fillrange function
|
# fillrange function
|
||||||
@ -850,7 +850,7 @@ end
|
|||||||
# d[k] = if v == :match
|
# d[k] = if v == :match
|
||||||
# match_color
|
# match_color
|
||||||
# elseif v == nothing
|
# elseif v == nothing
|
||||||
# colorscheme(RGBA(0,0,0,0))
|
# plot_color(RGBA(0,0,0,0))
|
||||||
# else
|
# else
|
||||||
# v
|
# v
|
||||||
# end
|
# end
|
||||||
@ -859,7 +859,9 @@ end
|
|||||||
function color_or_nothing!(d::KW, k::Symbol)
|
function color_or_nothing!(d::KW, k::Symbol)
|
||||||
v = d[k]
|
v = d[k]
|
||||||
d[k] = if v == nothing || v == false
|
d[k] = if v == nothing || v == false
|
||||||
colorscheme(RGBA(0,0,0,0))
|
plot_color(RGBA(0,0,0,0))
|
||||||
|
elseif v != :match
|
||||||
|
plot_color(v)
|
||||||
else
|
else
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
@ -935,6 +937,17 @@ function Base.getindex(series::Series, k::Symbol)
|
|||||||
series.d[k]
|
series.d[k]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Base.setindex!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v)
|
||||||
|
Base.setindex!(sp::Subplot, v, k::Symbol) = (sp.attr[k] = v)
|
||||||
|
Base.setindex!(axis::Axis, v, k::Symbol) = (axis.d[k] = v)
|
||||||
|
Base.setindex!(series::Series, v, k::Symbol) = (series.d[k] = v)
|
||||||
|
|
||||||
|
Base.get(plt::Plot, k::Symbol, v) = get(plt.attr, k, v)
|
||||||
|
Base.get(sp::Subplot, k::Symbol, v) = get(sp.attr, k, v)
|
||||||
|
Base.get(axis::Axis, k::Symbol, v) = get(axis.d, k, v)
|
||||||
|
Base.get(series::Series, k::Symbol, v) = get(series.d, k, v)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# update attr from an input dictionary
|
# update attr from an input dictionary
|
||||||
@ -1048,7 +1061,7 @@ end
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
function has_black_border_for_default(st::Symbol)
|
function has_black_border_for_default(st::Symbol)
|
||||||
like_histogram(st) || st in (:hexbin, :bar)
|
like_histogram(st) || st in (:hexbin, :bar, :shape)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1100,7 +1113,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
for s in (:line, :marker, :fill)
|
for s in (:line, :marker, :fill)
|
||||||
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
||||||
d[csym] = if d[csym] == :match
|
d[csym] = if d[csym] == :match
|
||||||
if has_black_border_for_default(d[:seriestype]) && csym == :line
|
if has_black_border_for_default(d[:seriestype]) && s == :line
|
||||||
plot_color(:black, d[asym])
|
plot_color(:black, d[asym])
|
||||||
else
|
else
|
||||||
d[:seriescolor]
|
d[:seriescolor]
|
||||||
@ -1112,7 +1125,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
|
|
||||||
# update markerstrokecolor
|
# update markerstrokecolor
|
||||||
d[:markerstrokecolor] = if d[:markerstrokecolor] == :match
|
d[:markerstrokecolor] = if d[:markerstrokecolor] == :match
|
||||||
sp[:foreground_color_subplot]
|
plot_color(sp[:foreground_color_subplot], d[:markerstrokealpha])
|
||||||
else
|
else
|
||||||
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -112,10 +112,10 @@ function gr_getcolorind(c)
|
|||||||
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
|
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
|
||||||
end
|
end
|
||||||
|
|
||||||
gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(c))
|
gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(cycle(c,1)))
|
||||||
gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(c))
|
gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(cycle(c,1)))
|
||||||
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(c))
|
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(cycle(c,1)))
|
||||||
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(c))
|
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(cycle(c,1)))
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -271,8 +271,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# draw the markers, one at a time
|
# draw the markers, one at a time
|
||||||
function gr_draw_markers(d::KW, x, y, msize, mz)
|
function gr_draw_markers(series::Series, x, y, msize, mz)
|
||||||
shape = d[:markershape]
|
shape = series[:markershape]
|
||||||
if shape != :none
|
if shape != :none
|
||||||
for i=1:length(x)
|
for i=1:length(x)
|
||||||
msi = cycle(msize, i)
|
msi = cycle(msize, i)
|
||||||
@ -280,18 +280,19 @@ function gr_draw_markers(d::KW, x, y, msize, mz)
|
|||||||
cfuncind = isa(shape, Shape) ? GR.setfillcolorind : GR.setmarkercolorind
|
cfuncind = isa(shape, Shape) ? GR.setfillcolorind : GR.setmarkercolorind
|
||||||
|
|
||||||
# draw a filled in shape, slightly bigger, to estimate a stroke
|
# draw a filled in shape, slightly bigger, to estimate a stroke
|
||||||
if d[:markerstrokewidth] > 0
|
if series[:markerstrokewidth] > 0
|
||||||
cfunc(cycle(d[:markerstrokecolor], i)) #, d[:markerstrokealpha])
|
cfunc(cycle(series[:markerstrokecolor], i)) #, series[:markerstrokealpha])
|
||||||
gr_draw_marker(x[i], y[i], msi + d[:markerstrokewidth], shape)
|
gr_draw_marker(x[i], y[i], msi + series[:markerstrokewidth], shape)
|
||||||
end
|
end
|
||||||
|
|
||||||
# draw the shape
|
# draw the shape
|
||||||
if mz == nothing
|
if mz == nothing
|
||||||
cfunc(cycle(d[:markercolor], i)) #, d[:markeralpha])
|
cfunc(cycle(series[:markercolor], i)) #, series[:markeralpha])
|
||||||
else
|
else
|
||||||
# pick a color from the pre-loaded gradient
|
# pick a color from the pre-loaded gradient
|
||||||
ci = round(Int, 1000 + cycle(mz, i) * 255)
|
ci = round(Int, 1000 + cycle(mz, i) * 255)
|
||||||
cfuncind(ci)
|
cfuncind(ci)
|
||||||
|
GR.settransparency(_gr_gradient_alpha[ci-999])
|
||||||
end
|
end
|
||||||
gr_draw_marker(x[i], y[i], msi, shape)
|
gr_draw_marker(x[i], y[i], msi, shape)
|
||||||
end
|
end
|
||||||
@ -300,12 +301,11 @@ end
|
|||||||
|
|
||||||
function gr_draw_markers(series::Series, x, y)
|
function gr_draw_markers(series::Series, x, y)
|
||||||
isempty(x) && return
|
isempty(x) && return
|
||||||
d = series.d
|
mz = normalize_zvals(series[:marker_z])
|
||||||
mz = normalize_zvals(d[:marker_z])
|
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
gr_draw_markers(d, x, y, d[:markersize], mz)
|
gr_draw_markers(series, x, y, series[:markersize], mz)
|
||||||
if mz != nothing
|
if mz != nothing
|
||||||
gr_colorbar(d[:subplot])
|
gr_colorbar(series[:subplot])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -403,13 +403,14 @@ gr_view_ydiff() = viewport_plotarea[4] - viewport_plotarea[3]
|
|||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const _gr_gradient_alpha = ones(256)
|
||||||
|
|
||||||
function gr_set_gradient(c) #, a)
|
function gr_set_gradient(c)
|
||||||
grad = isa(c, ColorGradient) ? c : cgrad()
|
grad = isa(c, ColorGradient) ? c : cgrad()
|
||||||
# grad = ColorGradient(grad, alpha=a)
|
|
||||||
for (i,z) in enumerate(linspace(0, 1, 256))
|
for (i,z) in enumerate(linspace(0, 1, 256))
|
||||||
c = grad[z]
|
c = grad[z]
|
||||||
GR.setcolorrep(999+i, red(c), green(c), blue(c), alpha(c))
|
GR.setcolorrep(999+i, red(c), green(c), blue(c))
|
||||||
|
_gr_gradient_alpha[i] = alpha(c)
|
||||||
end
|
end
|
||||||
grad
|
grad
|
||||||
end
|
end
|
||||||
@ -474,8 +475,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
draw_axes = true
|
draw_axes = true
|
||||||
# axes_2d = true
|
# axes_2d = true
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
st = series.d[:seriestype]
|
st = series[:seriestype]
|
||||||
if st in (:contour, :surface, :heatmap) || series.d[:marker_z] != nothing
|
if st in (:contour, :surface, :heatmap) || series[:marker_z] != nothing
|
||||||
cmap = true
|
cmap = true
|
||||||
end
|
end
|
||||||
if st == :pie
|
if st == :pie
|
||||||
@ -613,14 +614,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
|
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
|
||||||
|
|
||||||
for (idx, series) in enumerate(series_list(sp))
|
for (idx, series) in enumerate(series_list(sp))
|
||||||
d = series.d
|
st = series[:seriestype]
|
||||||
st = d[:seriestype]
|
|
||||||
|
|
||||||
# update the current stored gradient
|
# update the current stored gradient
|
||||||
if st in (:contour, :surface, :wireframe, :heatmap)
|
if st in (:contour, :surface, :wireframe, :heatmap)
|
||||||
gr_set_gradient(d[:fillcolor]) #, d[:fillalpha])
|
gr_set_gradient(series[:fillcolor]) #, series[:fillalpha])
|
||||||
elseif d[:marker_z] != nothing
|
elseif series[:marker_z] != nothing
|
||||||
d[:markercolor] = gr_set_gradient(d[:markercolor], d[:markeralpha])
|
series[:markercolor] = gr_set_gradient(series[:markercolor])
|
||||||
end
|
end
|
||||||
|
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
@ -635,12 +635,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
x, y, z = d[:x], d[:y], d[:z]
|
x, y, z = series[:x], series[:y], series[:z]
|
||||||
frng = d[:fillrange]
|
frng = series[:fillrange]
|
||||||
|
|
||||||
# recompute data
|
# recompute data
|
||||||
if st in (:contour, :surface, :wireframe)
|
if st in (:contour, :surface, :wireframe)
|
||||||
z = vec(transpose_z(d, z.surf, false))
|
z = vec(transpose_z(series, z.surf, false))
|
||||||
elseif ispolar(sp)
|
elseif ispolar(sp)
|
||||||
if frng != nothing
|
if frng != nothing
|
||||||
_, frng = convert_to_polar(x, frng, (rmin, rmax))
|
_, frng = convert_to_polar(x, frng, (rmin, rmax))
|
||||||
@ -653,7 +653,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
# do area fill
|
# do area fill
|
||||||
if frng != nothing
|
if frng != nothing
|
||||||
gr_set_fillcolor(d[:fillcolor]) #, d[:fillalpha])
|
gr_set_fillcolor(series[:fillcolor]) #, series[:fillalpha])
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
frng = isa(frng, Number) ? Float64[frng] : frng
|
frng = isa(frng, Number) ? Float64[frng] : frng
|
||||||
nx, ny, nf = length(x), length(y), length(frng)
|
nx, ny, nf = length(x), length(y), length(frng)
|
||||||
@ -669,24 +669,24 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
# draw the line(s)
|
# draw the line(s)
|
||||||
if st == :path
|
if st == :path
|
||||||
gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha])
|
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||||
gr_polyline(x, y)
|
gr_polyline(x, y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if d[:markershape] != :none
|
if series[:markershape] != :none
|
||||||
gr_draw_markers(series, x, y)
|
gr_draw_markers(series, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif st == :contour
|
elseif st == :contour
|
||||||
zmin, zmax = gr_lims(zaxis, false)
|
zmin, zmax = gr_lims(zaxis, false)
|
||||||
if typeof(d[:levels]) <: Array
|
if typeof(series[:levels]) <: Array
|
||||||
h = d[:levels]
|
h = series[:levels]
|
||||||
else
|
else
|
||||||
h = linspace(zmin, zmax, d[:levels])
|
h = linspace(zmin, zmax, series[:levels])
|
||||||
end
|
end
|
||||||
GR.setspace(zmin, zmax, 0, 90)
|
GR.setspace(zmin, zmax, 0, 90)
|
||||||
if d[:fillrange] != nothing
|
if series[:fillrange] != nothing
|
||||||
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
|
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
|
||||||
else
|
else
|
||||||
GR.contour(x, y, h, z, 1000)
|
GR.contour(x, y, h, z, 1000)
|
||||||
@ -713,7 +713,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
cmap && gr_colorbar(sp)
|
cmap && gr_colorbar(sp)
|
||||||
|
|
||||||
elseif st == :heatmap
|
elseif st == :heatmap
|
||||||
z = vec(transpose_z(d, z.surf, false))
|
z = vec(transpose_z(series, z.surf, false))
|
||||||
zmin, zmax = gr_lims(zaxis, true)
|
zmin, zmax = gr_lims(zaxis, true)
|
||||||
GR.setspace(zmin, zmax, 0, 90)
|
GR.setspace(zmin, zmax, 0, 90)
|
||||||
GR.surface(x, y, z, GR.OPTION_COLORED_MESH)
|
GR.surface(x, y, z, GR.OPTION_COLORED_MESH)
|
||||||
@ -723,13 +723,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# draw path
|
# draw path
|
||||||
if st == :path3d
|
if st == :path3d
|
||||||
if length(x) > 1
|
if length(x) > 1
|
||||||
gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha])
|
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||||
GR.polyline3d(x, y, z)
|
GR.polyline3d(x, y, z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# draw markers
|
# draw markers
|
||||||
if st == :scatter3d || d[:markershape] != :none
|
if st == :scatter3d || series[:markershape] != :none
|
||||||
x2, y2 = unzip(map(GR.wc3towc, x, y, z))
|
x2, y2 = unzip(map(GR.wc3towc, x, y, z))
|
||||||
gr_draw_markers(series, x2, y2)
|
gr_draw_markers(series, x2, y2)
|
||||||
end
|
end
|
||||||
@ -750,7 +750,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
ymin, ymax = ycenter - r, ycenter + r
|
ymin, ymax = ycenter - r, ycenter + r
|
||||||
end
|
end
|
||||||
labels = pie_labels(sp, series)
|
labels = pie_labels(sp, series)
|
||||||
slices = d[:y]
|
slices = series[:y]
|
||||||
numslices = length(slices)
|
numslices = length(slices)
|
||||||
total = sum(slices)
|
total = sum(slices)
|
||||||
a1 = 0
|
a1 = 0
|
||||||
@ -783,17 +783,27 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.selntran(1)
|
GR.selntran(1)
|
||||||
|
|
||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
|
for (i,rng) in enumerate(iter_segments(series[:x], series[:y]))
|
||||||
|
if length(rng) > 1
|
||||||
|
# connect to the beginning
|
||||||
|
rng = vcat(rng, rng[1])
|
||||||
|
|
||||||
|
# get the segments
|
||||||
|
x, y = series[:x][rng], series[:y][rng]
|
||||||
|
|
||||||
# draw the interior
|
# draw the interior
|
||||||
gr_set_fill(d[:fillcolor]) #, d[:fillalpha])
|
gr_set_fill(cycle(series[:fillcolor], i))
|
||||||
gr_polyline(d[:x], d[:y], GR.fillarea)
|
GR.fillarea(x, y)
|
||||||
|
|
||||||
# draw the shapes
|
# draw the shapes
|
||||||
gr_set_line(d[:linewidth], :solid, d[:linecolor]) #, d[:linealpha])
|
gr_set_line(series[:linewidth], :solid, cycle(series[:linecolor], i))
|
||||||
gr_polyline(d[:x], d[:y])
|
GR.polyline(x, y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
elseif st == :image
|
elseif st == :image
|
||||||
img = d[:z].surf
|
img = series[:z].surf
|
||||||
w, h = size(img)
|
w, h = size(img)
|
||||||
if eltype(img) <: Colors.AbstractGray
|
if eltype(img) <: Colors.AbstractGray
|
||||||
grey = round(UInt8, float(img) * 255)
|
grey = round(UInt8, float(img) * 255)
|
||||||
@ -823,11 +833,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
should_add_to_legend(series) || continue
|
should_add_to_legend(series) || continue
|
||||||
n += 1
|
n += 1
|
||||||
if typeof(series.d[:label]) <: Array
|
if typeof(series[:label]) <: Array
|
||||||
i += 1
|
i += 1
|
||||||
lab = series.d[:label][i]
|
lab = series[:label][i]
|
||||||
else
|
else
|
||||||
lab = series.d[:label]
|
lab = series[:label]
|
||||||
end
|
end
|
||||||
tbx, tby = gr_inqtext(0, 0, lab)
|
tbx, tby = gr_inqtext(0, 0, lab)
|
||||||
w = max(w, tbx[3] - tbx[1])
|
w = max(w, tbx[3] - tbx[1])
|
||||||
@ -845,13 +855,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
i = 0
|
i = 0
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
should_add_to_legend(series) || continue
|
should_add_to_legend(series) || continue
|
||||||
d = series.d
|
st = series[:seriestype]
|
||||||
st = d[:seriestype]
|
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||||
gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha])
|
|
||||||
if st == :path
|
if st == :path
|
||||||
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
gr_set_fill(d[:fillcolor]) #, d[:fillalpha])
|
gr_set_fill(series[:fillcolor]) #, series[:fillalpha])
|
||||||
l, r = xpos-0.07, xpos-0.01
|
l, r = xpos-0.07, xpos-0.01
|
||||||
b, t = ypos-0.4dy, ypos+0.4dy
|
b, t = ypos-0.4dy, ypos+0.4dy
|
||||||
x = [l, r, r, l, l]
|
x = [l, r, r, l, l]
|
||||||
@ -860,28 +869,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
gr_polyline(x, y)
|
gr_polyline(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
gr_draw_markers(d, xpos-[0.06,0.02], [ypos,ypos], 10, nothing)
|
if series[:markershape] != :none
|
||||||
# shape = d[:markershape]
|
gr_draw_markers(series, xpos-[0.06,0.02], [ypos,ypos], 10, nothing)
|
||||||
# if shape != :none #st == :scatter || d[:markershape] != :none
|
end
|
||||||
# msize = 10
|
|
||||||
# for xoff in [0.06,0.02]
|
if typeof(series[:label]) <: Array
|
||||||
# gr_set_markercolor(d[:markerstrokecolor]) #, d[:markerstrokealpha])
|
|
||||||
# gr_draw_marker(xpos-xoff, ypos, msize*1.1, shape)
|
|
||||||
# gr_set_markercolor(d[:markercolor], d[:markeralpha])
|
|
||||||
# gr_draw_marker(xpos-xoff, ypos, msize, shape)
|
|
||||||
# end
|
|
||||||
# # gr_setmarkershape(d)
|
|
||||||
# # if st == :path
|
|
||||||
# # gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos])
|
|
||||||
# # else
|
|
||||||
# # gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos])
|
|
||||||
# # end
|
|
||||||
# end
|
|
||||||
if typeof(d[:label]) <: Array
|
|
||||||
i += 1
|
i += 1
|
||||||
lab = d[:label][i]
|
lab = series[:label][i]
|
||||||
else
|
else
|
||||||
lab = d[:label]
|
lab = series[:label]
|
||||||
end
|
end
|
||||||
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
|
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
|
||||||
gr_set_textcolor(sp[:foreground_color_legend])
|
gr_set_textcolor(sp[:foreground_color_legend])
|
||||||
|
|||||||
@ -104,7 +104,7 @@ py_color(cs::AVec) = map(py_color, cs)
|
|||||||
py_color(grad::ColorGradient) = py_color(grad.colors)
|
py_color(grad::ColorGradient) = py_color(grad.colors)
|
||||||
|
|
||||||
function py_colormap(grad::ColorGradient)
|
function py_colormap(grad::ColorGradient)
|
||||||
pyvals = [(z, py_color(c[z])) for z in c.values]
|
pyvals = [(z, py_color(grad[z])) for z in grad.values]
|
||||||
pycolors.LinearSegmentedColormap[:from_list]("tmp", pyvals)
|
pycolors.LinearSegmentedColormap[:from_list]("tmp", pyvals)
|
||||||
end
|
end
|
||||||
py_colormap(c) = py_colormap(cgrad())
|
py_colormap(c) = py_colormap(cgrad())
|
||||||
@ -143,27 +143,27 @@ const _path_MOVETO = UInt8(1)
|
|||||||
const _path_LINETO = UInt8(2)
|
const _path_LINETO = UInt8(2)
|
||||||
const _path_CLOSEPOLY = UInt8(79)
|
const _path_CLOSEPOLY = UInt8(79)
|
||||||
|
|
||||||
# see http://matplotlib.org/users/path_tutorial.html
|
# # see http://matplotlib.org/users/path_tutorial.html
|
||||||
# and http://matplotlib.org/api/path_api.html#matplotlib.path.Path
|
# # and http://matplotlib.org/api/path_api.html#matplotlib.path.Path
|
||||||
function py_path(x, y)
|
# function py_path(x, y)
|
||||||
n = length(x)
|
# n = length(x)
|
||||||
mat = zeros(n+1, 2)
|
# mat = zeros(n+1, 2)
|
||||||
codes = zeros(UInt8, n+1)
|
# codes = zeros(UInt8, n+1)
|
||||||
lastnan = true
|
# lastnan = true
|
||||||
for i=1:n
|
# for i=1:n
|
||||||
mat[i,1] = x[i]
|
# mat[i,1] = x[i]
|
||||||
mat[i,2] = y[i]
|
# mat[i,2] = y[i]
|
||||||
nan = !ok(x[i], y[i])
|
# nan = !ok(x[i], y[i])
|
||||||
codes[i] = if nan && i>1
|
# codes[i] = if nan && i>1
|
||||||
_path_CLOSEPOLY
|
# _path_CLOSEPOLY
|
||||||
else
|
# else
|
||||||
lastnan ? _path_MOVETO : _path_LINETO
|
# lastnan ? _path_MOVETO : _path_LINETO
|
||||||
end
|
# end
|
||||||
lastnan = nan
|
# lastnan = nan
|
||||||
end
|
# end
|
||||||
codes[n+1] = _path_CLOSEPOLY
|
# codes[n+1] = _path_CLOSEPOLY
|
||||||
pypath.pymember("Path")(mat, codes)
|
# pypath.pymember("Path")(mat, codes)
|
||||||
end
|
# end
|
||||||
|
|
||||||
# get the marker shape
|
# get the marker shape
|
||||||
function py_marker(marker::Symbol)
|
function py_marker(marker::Symbol)
|
||||||
@ -220,29 +220,17 @@ function add_pyfixedformatter(cbar, vals::AVec)
|
|||||||
cbar[:update_ticks]()
|
cbar[:update_ticks]()
|
||||||
end
|
end
|
||||||
|
|
||||||
# # TODO: smoothing should be moved into the SliceIt method, should not touch backends
|
|
||||||
# function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool)
|
|
||||||
# if smooth
|
|
||||||
# xs, ys = regressionXY(d[:x], d[:y])
|
|
||||||
# ax[:plot](xs, ys,
|
|
||||||
# # linestyle = py_linestyle(:path, :dashdot),
|
|
||||||
# color = py_color(d[:linecolor]),
|
|
||||||
# linewidth = 2
|
|
||||||
# )
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Real) = handleSmooth(plt, ax, d, true)
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function fix_xy_lengths!(plt::Plot{PyPlotBackend}, d::KW)
|
function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series)
|
||||||
x, y = d[:x], d[:y]
|
x, y = series[:x], series[:y]
|
||||||
nx, ny = length(x), length(y)
|
nx, ny = length(x), length(y)
|
||||||
if !isa(get(d, :z, nothing), Surface) && nx != ny
|
if !isa(get(series.d, :z, nothing), Surface) && nx != ny
|
||||||
if nx < ny
|
if nx < ny
|
||||||
d[:x] = Float64[x[mod1(i,nx)] for i=1:ny]
|
series[:x] = Float64[x[mod1(i,nx)] for i=1:ny]
|
||||||
else
|
else
|
||||||
d[:y] = Float64[y[mod1(i,ny)] for i=1:nx]
|
series[:y] = Float64[y[mod1(i,ny)] for i=1:nx]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -258,14 +246,14 @@ function py_color_fix(c, x)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
py_linecolor(d::KW) = py_color(d[:linecolor]) #, d[:linealpha])
|
py_linecolor(series::Series) = py_color(series[:linecolor])
|
||||||
py_markercolor(d::KW) = py_color(d[:markercolor]) #, d[:markeralpha])
|
py_markercolor(series::Series) = py_color(series[:markercolor])
|
||||||
py_markerstrokecolor(d::KW) = py_color(d[:markerstrokecolor]) #, d[:markerstrokealpha])
|
py_markerstrokecolor(series::Series) = py_color(series[:markerstrokecolor])
|
||||||
py_fillcolor(d::KW) = py_color(d[:fillcolor]) #, d[:fillalpha])
|
py_fillcolor(series::Series) = py_color(series[:fillcolor])
|
||||||
|
|
||||||
py_linecolormap(d::KW) = py_colormap(d[:linecolor]) #, d[:linealpha])
|
py_linecolormap(series::Series) = py_colormap(series[:linecolor])
|
||||||
py_markercolormap(d::KW) = py_colormap(d[:markercolor]) #, d[:markeralpha])
|
py_markercolormap(series::Series) = py_colormap(series[:markercolor])
|
||||||
py_fillcolormap(d::KW) = py_colormap(d[:fillcolor]) #, d[:fillalpha])
|
py_fillcolormap(series::Series) = py_colormap(series[:fillcolor])
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -392,9 +380,9 @@ end
|
|||||||
# function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
# function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
||||||
|
|
||||||
function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||||
d = series.d
|
# d = series.d
|
||||||
st = d[:seriestype]
|
st = series[:seriestype]
|
||||||
sp = d[:subplot]
|
sp = series[:subplot]
|
||||||
ax = sp.o
|
ax = sp.o
|
||||||
|
|
||||||
if !(st in supported_types(plt.backend))
|
if !(st in supported_types(plt.backend))
|
||||||
@ -402,10 +390,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# PyPlot doesn't handle mismatched x/y
|
# PyPlot doesn't handle mismatched x/y
|
||||||
fix_xy_lengths!(plt, d)
|
fix_xy_lengths!(plt, series)
|
||||||
|
|
||||||
# ax = getAxis(plt, series)
|
# ax = getAxis(plt, series)
|
||||||
x, y, z = d[:x], d[:y], d[:z]
|
x, y, z = series[:x], series[:y], series[:z]
|
||||||
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||||
|
|
||||||
# handle zcolor and get c/cmap
|
# handle zcolor and get c/cmap
|
||||||
@ -418,7 +406,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
|
|
||||||
# pass in an integer value as an arg, but a levels list as a keyword arg
|
# pass in an integer value as an arg, but a levels list as a keyword arg
|
||||||
levels = d[:levels]
|
levels = series[:levels]
|
||||||
levelargs = if isscalar(levels)
|
levelargs = if isscalar(levels)
|
||||||
(levels)
|
(levels)
|
||||||
elseif isvector(levels)
|
elseif isvector(levels)
|
||||||
@ -432,14 +420,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
# line plot
|
# line plot
|
||||||
if st in (:path, :path3d, :steppre, :steppost)
|
if st in (:path, :path3d, :steppre, :steppost)
|
||||||
if d[:linewidth] > 0
|
if series[:linewidth] > 0
|
||||||
if d[:line_z] == nothing
|
if series[:line_z] == nothing
|
||||||
handle = ax[:plot](xyargs...;
|
handle = ax[:plot](xyargs...;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
color = py_linecolor(d),
|
color = py_linecolor(series),
|
||||||
linewidth = py_dpi_scale(plt, d[:linewidth]),
|
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||||
linestyle = py_linestyle(st, d[:linestyle]),
|
linestyle = py_linestyle(st, series[:linestyle]),
|
||||||
solid_capstyle = "round",
|
solid_capstyle = "round",
|
||||||
drawstyle = py_stepstyle(st)
|
drawstyle = py_stepstyle(st)
|
||||||
)[1]
|
)[1]
|
||||||
@ -450,18 +438,18 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
n = length(x) - 1
|
n = length(x) - 1
|
||||||
segments = Array(Any,n)
|
segments = Array(Any,n)
|
||||||
kw = KW(
|
kw = KW(
|
||||||
:label => d[:label],
|
:label => series[:label],
|
||||||
:zorder => plt.n,
|
:zorder => plt.n,
|
||||||
:cmap => py_linecolormap(d),
|
:cmap => py_linecolormap(series),
|
||||||
:linewidth => py_dpi_scale(plt, d[:linewidth]),
|
:linewidth => py_dpi_scale(plt, series[:linewidth]),
|
||||||
:linestyle => py_linestyle(st, d[:linestyle])
|
:linestyle => py_linestyle(st, series[:linestyle])
|
||||||
)
|
)
|
||||||
handle = if is3d(st)
|
handle = if is3d(st)
|
||||||
for i=1:n
|
for i=1:n
|
||||||
segments[i] = [(cycle(x,i), cycle(y,i), cycle(z,i)), (cycle(x,i+1), cycle(y,i+1), cycle(z,i+1))]
|
segments[i] = [(cycle(x,i), cycle(y,i), cycle(z,i)), (cycle(x,i+1), cycle(y,i+1), cycle(z,i+1))]
|
||||||
end
|
end
|
||||||
lc = pyart3d.Line3DCollection(segments; kw...)
|
lc = pyart3d.Line3DCollection(segments; kw...)
|
||||||
lc[:set_array](d[:line_z])
|
lc[:set_array](series[:line_z])
|
||||||
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
||||||
lc
|
lc
|
||||||
else
|
else
|
||||||
@ -469,7 +457,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
segments[i] = [(cycle(x,i), cycle(y,i)), (cycle(x,i+1), cycle(y,i+1))]
|
segments[i] = [(cycle(x,i), cycle(y,i)), (cycle(x,i+1), cycle(y,i+1))]
|
||||||
end
|
end
|
||||||
lc = pycollections.LineCollection(segments; kw...)
|
lc = pycollections.LineCollection(segments; kw...)
|
||||||
lc[:set_array](d[:line_z])
|
lc[:set_array](series[:line_z])
|
||||||
ax[:add_collection](lc)
|
ax[:add_collection](lc)
|
||||||
lc
|
lc
|
||||||
end
|
end
|
||||||
@ -477,7 +465,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
end
|
end
|
||||||
|
|
||||||
a = d[:arrow]
|
a = series[:arrow]
|
||||||
if a != nothing && !is3d(st) # TODO: handle 3d later
|
if a != nothing && !is3d(st) # TODO: handle 3d later
|
||||||
if typeof(a) != Arrow
|
if typeof(a) != Arrow
|
||||||
warn("Unexpected type for arrow: $(typeof(a))")
|
warn("Unexpected type for arrow: $(typeof(a))")
|
||||||
@ -486,10 +474,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
:arrowstyle => "simple,head_length=$(a.headlength),head_width=$(a.headwidth)",
|
:arrowstyle => "simple,head_length=$(a.headlength),head_width=$(a.headwidth)",
|
||||||
:shrinkA => 0,
|
:shrinkA => 0,
|
||||||
:shrinkB => 0,
|
:shrinkB => 0,
|
||||||
:edgecolor => py_linecolor(d),
|
:edgecolor => py_linecolor(series),
|
||||||
:facecolor => py_linecolor(d),
|
:facecolor => py_linecolor(series),
|
||||||
:linewidth => py_dpi_scale(plt, d[:linewidth]),
|
:linewidth => py_dpi_scale(plt, series[:linewidth]),
|
||||||
:linestyle => py_linestyle(st, d[:linestyle]),
|
:linestyle => py_linestyle(st, series[:linestyle]),
|
||||||
)
|
)
|
||||||
add_arrows(x, y) do xyprev, xy
|
add_arrows(x, y) do xyprev, xy
|
||||||
ax[:annotate]("",
|
ax[:annotate]("",
|
||||||
@ -504,53 +492,16 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# if st == :bar
|
|
||||||
# bw = d[:bar_width]
|
|
||||||
# if bw == nothing
|
|
||||||
# bw = mean(diff(isvertical(d) ? x : y))
|
|
||||||
# end
|
|
||||||
# extrakw[isvertical(d) ? :width : :height] = bw
|
|
||||||
# fr = get(d, :fillrange, nothing)
|
|
||||||
# if fr != nothing
|
|
||||||
# extrakw[:bottom] = fr
|
|
||||||
# d[:fillrange] = nothing
|
|
||||||
# end
|
|
||||||
# handle = ax[isvertical(d) ? :bar : :barh](x, y;
|
|
||||||
# label = d[:label],
|
|
||||||
# zorder = d[:series_plotindex],
|
|
||||||
# color = py_fillcolor(d),
|
|
||||||
# edgecolor = py_linecolor(d),
|
|
||||||
# linewidth = d[:linewidth],
|
|
||||||
# align = d[:bar_edges] ? "edge" : "center",
|
|
||||||
# extrakw...
|
|
||||||
# )[1]
|
|
||||||
# push!(handles, handle)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# if st == :sticks
|
|
||||||
# extrakw[isvertical(d) ? :width : :height] = 0.0
|
|
||||||
# handle = ax[isvertical(d) ? :bar : :barh](x, y;
|
|
||||||
# label = d[:label],
|
|
||||||
# zorder = d[:series_plotindex],
|
|
||||||
# color = py_linecolor(d),
|
|
||||||
# edgecolor = py_linecolor(d),
|
|
||||||
# linewidth = d[:linewidth],
|
|
||||||
# align = "center",
|
|
||||||
# extrakw...
|
|
||||||
# )[1]
|
|
||||||
# push!(handles, handle)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# add markers?
|
# add markers?
|
||||||
if d[:markershape] != :none && st in (:path, :scatter, :path3d,
|
if series[:markershape] != :none && st in (:path, :scatter, :path3d,
|
||||||
:scatter3d, :steppre, :steppost,
|
:scatter3d, :steppre, :steppost,
|
||||||
:bar)
|
:bar)
|
||||||
extrakw = KW()
|
extrakw = KW()
|
||||||
if d[:marker_z] == nothing
|
if series[:marker_z] == nothing
|
||||||
extrakw[:c] = py_color_fix(py_markercolor(d), x)
|
extrakw[:c] = py_color_fix(py_markercolor(series), x)
|
||||||
else
|
else
|
||||||
extrakw[:c] = convert(Vector{Float64}, d[:marker_z])
|
extrakw[:c] = convert(Vector{Float64}, series[:marker_z])
|
||||||
extrakw[:cmap] = py_markercolormap(d)
|
extrakw[:cmap] = py_markercolormap(series)
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
if is_2tuple(clims)
|
if is_2tuple(clims)
|
||||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||||
@ -558,72 +509,23 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
end
|
end
|
||||||
xyargs = if st == :bar && !isvertical(d)
|
xyargs = if st == :bar && !isvertical(series)
|
||||||
(y, x)
|
(y, x)
|
||||||
else
|
else
|
||||||
xyargs
|
xyargs
|
||||||
end
|
end
|
||||||
handle = ax[:scatter](xyargs...;
|
handle = ax[:scatter](xyargs...;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex] + 0.5,
|
zorder = series[:series_plotindex] + 0.5,
|
||||||
marker = py_marker(d[:markershape]),
|
marker = py_marker(series[:markershape]),
|
||||||
s = py_dpi_scale(plt, d[:markersize] .^ 2),
|
s = py_dpi_scale(plt, series[:markersize] .^ 2),
|
||||||
edgecolors = py_markerstrokecolor(d),
|
edgecolors = py_markerstrokecolor(series),
|
||||||
linewidths = py_dpi_scale(plt, d[:markerstrokewidth]),
|
linewidths = py_dpi_scale(plt, series[:markerstrokewidth]),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
end
|
end
|
||||||
|
|
||||||
# if st == :histogram
|
|
||||||
# handle = ax[:hist](y;
|
|
||||||
# label = d[:label],
|
|
||||||
# zorder = d[:series_plotindex],
|
|
||||||
# color = py_fillcolor(d),
|
|
||||||
# edgecolor = py_linecolor(d),
|
|
||||||
# linewidth = d[:linewidth],
|
|
||||||
# bins = d[:bins],
|
|
||||||
# normed = d[:normalize],
|
|
||||||
# weights = d[:weights],
|
|
||||||
# orientation = (isvertical(d) ? "vertical" : "horizontal"),
|
|
||||||
# histtype = (d[:bar_position] == :stack ? "barstacked" : "bar")
|
|
||||||
# )[3]
|
|
||||||
# push!(handles, handle)
|
|
||||||
|
|
||||||
# # expand the extrema... handle is a list of Rectangle objects
|
|
||||||
# for rect in handle
|
|
||||||
# xmin, ymin, xmax, ymax = rect[:get_bbox]()[:extents]
|
|
||||||
# expand_extrema!(sp, xmin, xmax, ymin, ymax)
|
|
||||||
# # expand_extrema!(sp[:xaxis], (xmin, xmax))
|
|
||||||
# # expand_extrema!(sp[:yaxis], (ymin, ymax))
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# if st == :histogram2d
|
|
||||||
# clims = sp[:clims]
|
|
||||||
# if is_2tuple(clims)
|
|
||||||
# isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
|
||||||
# isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
|
||||||
# end
|
|
||||||
# handle = ax[:hist2d](x, y;
|
|
||||||
# label = d[:label],
|
|
||||||
# zorder = d[:series_plotindex],
|
|
||||||
# bins = d[:bins],
|
|
||||||
# normed = d[:normalize],
|
|
||||||
# weights = d[:weights],
|
|
||||||
# cmap = py_fillcolormap(d), # applies to the pcolorfast object
|
|
||||||
# extrakw...
|
|
||||||
# )[4]
|
|
||||||
# push!(handles, handle)
|
|
||||||
# needs_colorbar = true
|
|
||||||
|
|
||||||
# # expand the extrema... handle is a AxesImage object
|
|
||||||
# expand_extrema!(sp, handle[:get_extent]()...)
|
|
||||||
# # xmin, xmax, ymin, ymax = handle[:get_extent]()
|
|
||||||
# # expand_extrema!(sp[:xaxis], (xmin, xmax))
|
|
||||||
# # expand_extrema!(sp[:yaxis], (ymin, ymax))
|
|
||||||
# end
|
|
||||||
|
|
||||||
if st == :hexbin
|
if st == :hexbin
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
if is_2tuple(clims)
|
if is_2tuple(clims)
|
||||||
@ -631,33 +533,20 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||||
end
|
end
|
||||||
handle = ax[:hexbin](x, y;
|
handle = ax[:hexbin](x, y;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
gridsize = d[:bins],
|
gridsize = series[:bins],
|
||||||
linewidths = py_dpi_scale(plt, d[:linewidth]),
|
linewidths = py_dpi_scale(plt, series[:linewidth]),
|
||||||
edgecolors = py_linecolor(d),
|
edgecolors = py_linecolor(series),
|
||||||
cmap = py_fillcolormap(d), # applies to the pcolorfast object
|
cmap = py_fillcolormap(series), # applies to the pcolorfast object
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# if st in (:hline,:vline)
|
|
||||||
# for yi in d[:y]
|
|
||||||
# func = ax[st == :hline ? :axhline : :axvline]
|
|
||||||
# handle = func(yi;
|
|
||||||
# linewidth=d[:linewidth],
|
|
||||||
# color=py_linecolor(d),
|
|
||||||
# linestyle=py_linestyle(st, d[:linestyle])
|
|
||||||
# )
|
|
||||||
# push!(handles, handle)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
if st in (:contour, :contour3d)
|
if st in (:contour, :contour3d)
|
||||||
# z = z.surf'
|
z = transpose_z(series, z.surf)
|
||||||
z = transpose_z(d, z.surf)
|
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
|
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
@ -672,21 +561,21 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
# contour lines
|
# contour lines
|
||||||
handle = ax[:contour](x, y, z, levelargs...;
|
handle = ax[:contour](x, y, z, levelargs...;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
linewidths = py_dpi_scale(plt, d[:linewidth]),
|
linewidths = py_dpi_scale(plt, series[:linewidth]),
|
||||||
linestyles = py_linestyle(st, d[:linestyle]),
|
linestyles = py_linestyle(st, series[:linestyle]),
|
||||||
cmap = py_linecolormap(d),
|
cmap = py_linecolormap(series),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
|
|
||||||
# contour fills
|
# contour fills
|
||||||
if d[:fillrange] != nothing
|
if series[:fillrange] != nothing
|
||||||
handle = ax[:contourf](x, y, z, levelargs...;
|
handle = ax[:contourf](x, y, z, levelargs...;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex] + 0.5,
|
zorder = series[:series_plotindex] + 0.5,
|
||||||
cmap = py_fillcolormap(d),
|
cmap = py_fillcolormap(series),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
@ -698,13 +587,13 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
x, y, z = map(Array, (x,y,z))
|
x, y, z = map(Array, (x,y,z))
|
||||||
if !ismatrix(x) || !ismatrix(y)
|
if !ismatrix(x) || !ismatrix(y)
|
||||||
x = repmat(x', length(y), 1)
|
x = repmat(x', length(y), 1)
|
||||||
y = repmat(y, 1, length(d[:x]))
|
y = repmat(y, 1, length(series[:x]))
|
||||||
end
|
end
|
||||||
# z = z'
|
# z = z'
|
||||||
z = transpose_z(d, z)
|
z = transpose_z(series, z)
|
||||||
if st == :surface
|
if st == :surface
|
||||||
if d[:marker_z] != nothing
|
if series[:marker_z] != nothing
|
||||||
extrakw[:facecolors] = py_shading(d[:fillcolor], d[:marker_z], d[:fillalpha])
|
extrakw[:facecolors] = py_shading(series[:fillcolor], series[:marker_z], series[:fillalpha])
|
||||||
extrakw[:shade] = false
|
extrakw[:shade] = false
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
if is_2tuple(clims)
|
if is_2tuple(clims)
|
||||||
@ -712,28 +601,28 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
extrakw[:cmap] = py_fillcolormap(d)
|
extrakw[:cmap] = py_fillcolormap(series)
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z;
|
handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
rstride = 1,
|
rstride = 1,
|
||||||
cstride = 1,
|
cstride = 1,
|
||||||
linewidth = py_dpi_scale(plt, d[:linewidth]),
|
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||||
edgecolor = py_linecolor(d),
|
edgecolor = py_linecolor(series),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
|
|
||||||
# contours on the axis planes
|
# contours on the axis planes
|
||||||
if d[:contours]
|
if series[:contours]
|
||||||
for (zdir,mat) in (("x",x), ("y",y), ("z",z))
|
for (zdir,mat) in (("x",x), ("y",y), ("z",z))
|
||||||
offset = (zdir == "y" ? maximum : minimum)(mat)
|
offset = (zdir == "y" ? maximum : minimum)(mat)
|
||||||
handle = ax[:contourf](x, y, z, levelargs...;
|
handle = ax[:contourf](x, y, z, levelargs...;
|
||||||
zdir = zdir,
|
zdir = zdir,
|
||||||
cmap = py_fillcolormap(d),
|
cmap = py_fillcolormap(series),
|
||||||
offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane
|
offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
@ -754,11 +643,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||||
end
|
end
|
||||||
handle = ax[:plot_trisurf](x, y, z;
|
handle = ax[:plot_trisurf](x, y, z;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
cmap = py_fillcolormap(d),
|
cmap = py_fillcolormap(series),
|
||||||
linewidth = py_dpi_scale(plt, d[:linewidth]),
|
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||||
edgecolor = py_linecolor(d),
|
edgecolor = py_linecolor(series),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
@ -770,7 +659,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
if st == :image
|
if st == :image
|
||||||
# @show typeof(z)
|
# @show typeof(z)
|
||||||
img = Array(transpose_z(d, z.surf))
|
img = Array(transpose_z(series, z.surf))
|
||||||
z = if eltype(img) <: Colors.AbstractGray
|
z = if eltype(img) <: Colors.AbstractGray
|
||||||
float(img)
|
float(img)
|
||||||
elseif eltype(img) <: Colorant
|
elseif eltype(img) <: Colorant
|
||||||
@ -779,7 +668,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
z # hopefully it's in a data format that will "just work" with imshow
|
z # hopefully it's in a data format that will "just work" with imshow
|
||||||
end
|
end
|
||||||
handle = ax[:imshow](z;
|
handle = ax[:imshow](z;
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
cmap = py_colormap([:black, :white]),
|
cmap = py_colormap([:black, :white]),
|
||||||
vmin = 0.0,
|
vmin = 0.0,
|
||||||
vmax = 1.0
|
vmax = 1.0
|
||||||
@ -789,11 +678,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# expand extrema... handle is AxesImage object
|
# expand extrema... handle is AxesImage object
|
||||||
xmin, xmax, ymax, ymin = handle[:get_extent]()
|
xmin, xmax, ymax, ymin = handle[:get_extent]()
|
||||||
expand_extrema!(sp, xmin, xmax, ymin, ymax)
|
expand_extrema!(sp, xmin, xmax, ymin, ymax)
|
||||||
# sp[:yaxis].d[:flip] = true
|
# sp[:yaxis].series[:flip] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if st == :heatmap
|
if st == :heatmap
|
||||||
x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(d, z.surf)
|
x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(series, z.surf)
|
||||||
# if !(eltype(z) <: Number)
|
# if !(eltype(z) <: Number)
|
||||||
# z, discrete_colorbar_values = indices_and_unique_values(z)
|
# z, discrete_colorbar_values = indices_and_unique_values(z)
|
||||||
# end
|
# end
|
||||||
@ -809,10 +698,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
handle = ax[:pcolormesh](x, y, z;
|
handle = ax[:pcolormesh](x, y, z;
|
||||||
label = d[:label],
|
label = series[:label],
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
cmap = py_fillcolormap(d),
|
cmap = py_fillcolormap(series),
|
||||||
edgecolors = (d[:linewidth] > 0 ? py_linecolor(d) : "face"),
|
edgecolors = (series[:linewidth] > 0 ? py_linecolor(series) : "face"),
|
||||||
extrakw...
|
extrakw...
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
@ -830,16 +719,32 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if st == :shape
|
if st == :shape
|
||||||
path = py_path(x, y)
|
handle = []
|
||||||
patches = pypatches.pymember("PathPatch")(path;
|
for (i,rng) in enumerate(iter_segments(x, y))
|
||||||
label = d[:label],
|
if length(rng) > 1
|
||||||
zorder = d[:series_plotindex],
|
path = pypath.pymember("Path")(hcat(x[rng], y[rng]))
|
||||||
edgecolor = py_linecolor(d),
|
patches = pypatches.pymember("PathPatch")(
|
||||||
facecolor = py_fillcolor(d),
|
path;
|
||||||
linewidth = py_dpi_scale(plt, d[:linewidth]),
|
label = series[:label],
|
||||||
|
zorder = series[:series_plotindex],
|
||||||
|
edgecolor = py_color(cycle(series[:linecolor], i)),
|
||||||
|
facecolor = py_color(cycle(series[:fillcolor], i)),
|
||||||
|
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||||
fill = true
|
fill = true
|
||||||
)
|
)
|
||||||
handle = ax[:add_patch](patches)
|
push!(handle, ax[:add_patch](patches))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# path = py_path(x, y)
|
||||||
|
# patches = pypatches.pymember("PathPatch")(path;
|
||||||
|
# label = series[:label],
|
||||||
|
# zorder = series[:series_plotindex],
|
||||||
|
# edgecolor = py_linecolor(series),
|
||||||
|
# facecolor = py_fillcolor(series),
|
||||||
|
# linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||||
|
# fill = true
|
||||||
|
# )
|
||||||
|
# handle = ax[:add_patch](patches)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -858,10 +763,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
expand_extrema!(sp, -lim, lim, -lim, lim)
|
expand_extrema!(sp, -lim, lim, -lim, lim)
|
||||||
end
|
end
|
||||||
|
|
||||||
d[:serieshandle] = handles
|
series[:serieshandle] = handles
|
||||||
|
|
||||||
# # smoothing
|
# # smoothing
|
||||||
# handleSmooth(plt, ax, d, d[:smooth])
|
# handleSmooth(plt, ax, series, series[:smooth])
|
||||||
|
|
||||||
# add the colorbar legend
|
# add the colorbar legend
|
||||||
if needs_colorbar && sp[:colorbar] != :none
|
if needs_colorbar && sp[:colorbar] != :none
|
||||||
@ -886,55 +791,29 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# handle area filling
|
# handle area filling
|
||||||
fillrange = d[:fillrange]
|
fillrange = series[:fillrange]
|
||||||
if fillrange != nothing && st != :contour
|
if fillrange != nothing && st != :contour
|
||||||
f, dim1, dim2 = if isvertical(d)
|
f, dim1, dim2 = if isvertical(series)
|
||||||
:fill_between, x, y
|
:fill_between, x, y
|
||||||
else
|
else
|
||||||
:fill_betweenx, y, x
|
:fill_betweenx, y, x
|
||||||
end
|
end
|
||||||
|
n = length(dim1)
|
||||||
args = if typeof(fillrange) <: Union{Real, AVec}
|
args = if typeof(fillrange) <: Union{Real, AVec}
|
||||||
dim1, fillrange, dim2
|
dim1, expand_data(fillrange, n), dim2
|
||||||
else
|
elseif is_2tuple(fillrange)
|
||||||
dim1, fillrange...
|
dim1, expand_data(fillrange[1], n), expand_data(fillrange[2], n)
|
||||||
end
|
end
|
||||||
|
|
||||||
handle = ax[f](args...;
|
handle = ax[f](args...;
|
||||||
zorder = d[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
facecolor = py_fillcolor(d),
|
facecolor = py_fillcolor(series),
|
||||||
linewidths = 0
|
linewidths = 0
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# function update_limits!(sp::Subplot{PyPlotBackend}, series::Series, letters)
|
|
||||||
# for letter in letters
|
|
||||||
# py_set_lims(sp.o, sp[Symbol(letter, :axis)])
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# function _series_updated(plt::Plot{PyPlotBackend}, series::Series)
|
|
||||||
# d = series.d
|
|
||||||
# for handle in get(d, :serieshandle, [])
|
|
||||||
# if is3d(series)
|
|
||||||
# handle[:set_data](d[:x], d[:y])
|
|
||||||
# handle[:set_3d_properties](d[:z])
|
|
||||||
# else
|
|
||||||
# try
|
|
||||||
# handle[:set_data](d[:x], d[:y])
|
|
||||||
# catch
|
|
||||||
# handle[:set_offsets](hcat(d[:x], d[:y]))
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# update_limits!(d[:subplot], series, is3d(series) ? (:x,:y,:z) : (:x,:y))
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function py_set_lims(ax, axis::Axis)
|
function py_set_lims(ax, axis::Axis)
|
||||||
@ -1029,7 +908,6 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
w, h = plt[:size]
|
w, h = plt[:size]
|
||||||
fig = plt.o
|
fig = plt.o
|
||||||
fig[:clear]()
|
fig[:clear]()
|
||||||
# fig[:set_size_inches](px2inch(w), px2inch(h), forward = true)
|
|
||||||
dpi = plt[:dpi]
|
dpi = plt[:dpi]
|
||||||
fig[:set_size_inches](w/dpi, h/dpi, forward = true)
|
fig[:set_size_inches](w/dpi, h/dpi, forward = true)
|
||||||
fig[:set_facecolor](py_color(plt[:background_color_outside]))
|
fig[:set_facecolor](py_color(plt[:background_color_outside]))
|
||||||
@ -1175,21 +1053,6 @@ end
|
|||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
# function _remove_axis(plt::Plot{PyPlotBackend}, isx::Bool)
|
|
||||||
# if isx
|
|
||||||
# plot!(plt, xticks=zeros(0), xlabel="")
|
|
||||||
# else
|
|
||||||
# plot!(plt, yticks=zeros(0), ylabel="")
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# function _expand_limits(lims, plt::Plot{PyPlotBackend}, isx::Bool)
|
|
||||||
# pltlims = plt.o.ax[isx ? :get_xbound : :get_ybound]()
|
|
||||||
# _expand_limits(lims, pltlims)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
|
||||||
|
|
||||||
const _pyplot_legend_pos = KW(
|
const _pyplot_legend_pos = KW(
|
||||||
:right => "right",
|
:right => "right",
|
||||||
:left => "center left",
|
:left => "center left",
|
||||||
@ -1210,12 +1073,15 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
|
|||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
if should_add_to_legend(series)
|
if should_add_to_legend(series)
|
||||||
# add a line/marker and a label
|
# add a line/marker and a label
|
||||||
push!(handles, if series.d[:seriestype] == :histogram
|
push!(handles, if series[:seriestype] == :shape
|
||||||
PyPlot.plt[:Line2D]((0,1),(0,0), color=py_fillcolor(series.d), linewidth=py_dpi_scale(plt, 4))
|
PyPlot.plt[:Line2D]((0,1),(0,0),
|
||||||
|
color = py_color(cycle(series[:fillcolor],1)),
|
||||||
|
linewidth = py_dpi_scale(plt, 4)
|
||||||
|
)
|
||||||
else
|
else
|
||||||
series.d[:serieshandle][1]
|
series[:serieshandle][1]
|
||||||
end)
|
end)
|
||||||
push!(labels, series.d[:label])
|
push!(labels, series[:label])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -14,13 +14,13 @@ compute_angle(v::P2) = (angle = atan2(v[2], v[1]); angle < 0 ? 2π - angle : ang
|
|||||||
immutable Shape
|
immutable Shape
|
||||||
x::Vector{Float64}
|
x::Vector{Float64}
|
||||||
y::Vector{Float64}
|
y::Vector{Float64}
|
||||||
function Shape(x::AVec, y::AVec)
|
# function Shape(x::AVec, y::AVec)
|
||||||
if x[1] != x[end] || y[1] != y[end]
|
# # if x[1] != x[end] || y[1] != y[end]
|
||||||
new(vcat(x, x[1]), vcat(y, y[1]))
|
# # new(vcat(x, x[1]), vcat(y, y[1]))
|
||||||
else
|
# # else
|
||||||
new(x, y)
|
# new(x, y)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
Shape(verts::AVec) = Shape(unzip(verts)...)
|
Shape(verts::AVec) = Shape(unzip(verts)...)
|
||||||
|
|
||||||
|
|||||||
@ -653,6 +653,8 @@ end
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Violin Plot
|
# Violin Plot
|
||||||
|
|
||||||
|
const _violin_warned = [false]
|
||||||
|
|
||||||
# if the user has KernelDensity installed, use this for violin plots.
|
# if the user has KernelDensity installed, use this for violin plots.
|
||||||
# otherwise, just use a histogram
|
# otherwise, just use a histogram
|
||||||
if is_installed("KernelDensity")
|
if is_installed("KernelDensity")
|
||||||
@ -668,7 +670,11 @@ if is_installed("KernelDensity")
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
@eval function violin_coords(y; trim::Bool=false)
|
@eval function violin_coords(y; trim::Bool=false)
|
||||||
edges, widths = hist(y, 30)
|
if !_violin_warned[1]
|
||||||
|
warn("Install the KernelDensity package for best results.")
|
||||||
|
_violin_warned[1] = true
|
||||||
|
end
|
||||||
|
edges, widths = my_hist(y, 10)
|
||||||
centers = 0.5 * (edges[1:end-1] + edges[2:end])
|
centers = 0.5 * (edges[1:end-1] + edges[2:end])
|
||||||
ymin, ymax = extrema(y)
|
ymin, ymax = extrema(y)
|
||||||
vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax)
|
vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax)
|
||||||
|
|||||||
@ -257,17 +257,17 @@ end
|
|||||||
# # plotting arbitrary shapes/polygons
|
# # plotting arbitrary shapes/polygons
|
||||||
|
|
||||||
@recipe function f(shape::Shape)
|
@recipe function f(shape::Shape)
|
||||||
seriestype := :shape
|
seriestype --> :shape
|
||||||
shape_coords(shape)
|
shape_coords(shape)
|
||||||
end
|
end
|
||||||
|
|
||||||
@recipe function f(shapes::AVec{Shape})
|
@recipe function f(shapes::AVec{Shape})
|
||||||
seriestype := :shape
|
seriestype --> :shape
|
||||||
shape_coords(shapes)
|
shape_coords(shapes)
|
||||||
end
|
end
|
||||||
|
|
||||||
@recipe function f(shapes::AMat{Shape})
|
@recipe function f(shapes::AMat{Shape})
|
||||||
seriestype := :shape
|
seriestype --> :shape
|
||||||
for j in 1:size(shapes,2)
|
for j in 1:size(shapes,2)
|
||||||
@series shape_coords(vec(shapes[:,j]))
|
@series shape_coords(vec(shapes[:,j]))
|
||||||
end
|
end
|
||||||
|
|||||||
19
src/utils.jl
19
src/utils.jl
@ -166,7 +166,6 @@ end
|
|||||||
|
|
||||||
type SegmentsIterator
|
type SegmentsIterator
|
||||||
args::Tuple
|
args::Tuple
|
||||||
# nextidx::Int
|
|
||||||
n::Int
|
n::Int
|
||||||
end
|
end
|
||||||
function iter_segments(args...)
|
function iter_segments(args...)
|
||||||
@ -176,13 +175,13 @@ function iter_segments(args...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# helpers to figure out if there are NaN values in a list of array types
|
# helpers to figure out if there are NaN values in a list of array types
|
||||||
anynan(i::Int, args...) = any(a -> !isfinite(cycle(a,i)), args)
|
anynan(i::Int, args::Tuple) = any(a -> !isfinite(cycle(a,i)), args)
|
||||||
anynan(istart::Int, iend::Int, args...) = any(i -> anynan(i, args...), istart:iend)
|
anynan(istart::Int, iend::Int, args::Tuple) = any(i -> anynan(i, args), istart:iend)
|
||||||
allnan(istart::Int, iend::Int, args...) = all(i -> anynan(i, args...), istart:iend)
|
allnan(istart::Int, iend::Int, args::Tuple) = all(i -> anynan(i, args), istart:iend)
|
||||||
|
|
||||||
function Base.start(itr::SegmentsIterator)
|
function Base.start(itr::SegmentsIterator)
|
||||||
nextidx = 1
|
nextidx = 1
|
||||||
if anynan(1, itr.args...)
|
if anynan(1, itr.args)
|
||||||
_, nextidx = next(itr, 1)
|
_, nextidx = next(itr, 1)
|
||||||
end
|
end
|
||||||
nextidx
|
nextidx
|
||||||
@ -193,7 +192,7 @@ function Base.next(itr::SegmentsIterator, nextidx::Int)
|
|||||||
|
|
||||||
# find the next NaN, and iend is the one before
|
# find the next NaN, and iend is the one before
|
||||||
while i <= itr.n + 1
|
while i <= itr.n + 1
|
||||||
if i > itr.n || anynan(i, itr.args...)
|
if i > itr.n || anynan(i, itr.args)
|
||||||
# done... array end or found NaN
|
# done... array end or found NaN
|
||||||
iend = i-1
|
iend = i-1
|
||||||
break
|
break
|
||||||
@ -203,7 +202,7 @@ function Base.next(itr::SegmentsIterator, nextidx::Int)
|
|||||||
|
|
||||||
# find the next non-NaN, and set nextidx
|
# find the next non-NaN, and set nextidx
|
||||||
while i <= itr.n
|
while i <= itr.n
|
||||||
if !anynan(i, itr.args...)
|
if !anynan(i, itr.args)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
i += 1
|
i += 1
|
||||||
@ -229,6 +228,8 @@ Base.cycle(v::AVec, indices::AVec{Int}) = map(i -> cycle(v,i), indices)
|
|||||||
Base.cycle(v::AMat, indices::AVec{Int}) = map(i -> cycle(v,i), indices)
|
Base.cycle(v::AMat, indices::AVec{Int}) = map(i -> cycle(v,i), indices)
|
||||||
Base.cycle(v, idx::AVec{Int}) = v
|
Base.cycle(v, idx::AVec{Int}) = v
|
||||||
|
|
||||||
|
Base.cycle(grad::ColorGradient, idx) = cycle(grad.colors, idx)
|
||||||
|
|
||||||
makevec(v::AVec) = v
|
makevec(v::AVec) = v
|
||||||
makevec{T}(v::T) = T[v]
|
makevec{T}(v::T) = T[v]
|
||||||
|
|
||||||
@ -264,6 +265,7 @@ function _expand_limits(lims, x)
|
|||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expand_data(v, n::Integer) = [cycle(v, i) for i=1:n]
|
||||||
|
|
||||||
# if the type exists in a list, replace the first occurence. otherwise add it to the end
|
# if the type exists in a list, replace the first occurence. otherwise add it to the end
|
||||||
function addOrReplace(v::AbstractVector, t::DataType, args...; kw...)
|
function addOrReplace(v::AbstractVector, t::DataType, args...; kw...)
|
||||||
@ -368,6 +370,7 @@ is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2
|
|||||||
|
|
||||||
|
|
||||||
isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert)
|
isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert)
|
||||||
|
isvertical(series::Series) = isvertical(series.d)
|
||||||
|
|
||||||
|
|
||||||
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
||||||
@ -427,7 +430,7 @@ end
|
|||||||
# this is a helper function to determine whether we need to transpose a surface matrix.
|
# this is a helper function to determine whether we need to transpose a surface matrix.
|
||||||
# it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa
|
# it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa
|
||||||
# for example: PyPlot sends rows to y, so transpose_on_match should be true
|
# for example: PyPlot sends rows to y, so transpose_on_match should be true
|
||||||
function transpose_z(d::KW, z, transpose_on_match::Bool = true)
|
function transpose_z(d, z, transpose_on_match::Bool = true)
|
||||||
if d[:match_dimensions] == transpose_on_match
|
if d[:match_dimensions] == transpose_on_match
|
||||||
z'
|
z'
|
||||||
else
|
else
|
||||||
|
|||||||
@ -23,14 +23,14 @@ facts("PyPlot") do
|
|||||||
@fact pyplot() --> Plots.PyPlotBackend()
|
@fact pyplot() --> Plots.PyPlotBackend()
|
||||||
@fact backend() --> Plots.PyPlotBackend()
|
@fact backend() --> Plots.PyPlotBackend()
|
||||||
|
|
||||||
image_comparison_facts(:pyplot, skip=[30], eps=img_eps)
|
image_comparison_facts(:pyplot, skip=[], eps=img_eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
facts("GR") do
|
facts("GR") do
|
||||||
@fact gr() --> Plots.GRBackend()
|
@fact gr() --> Plots.GRBackend()
|
||||||
@fact backend() --> Plots.GRBackend()
|
@fact backend() --> Plots.GRBackend()
|
||||||
|
|
||||||
@linux_only image_comparison_facts(:gr, skip=[30], eps=img_eps)
|
@linux_only image_comparison_facts(:gr, skip=[], eps=img_eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
facts("Plotly") do
|
facts("Plotly") do
|
||||||
|
|||||||
@ -11,6 +11,8 @@ Pkg.build("GR")
|
|||||||
# Pkg.clone("https://github.com/tbreloff/ExamplePlots.jl.git");
|
# Pkg.clone("https://github.com/tbreloff/ExamplePlots.jl.git");
|
||||||
Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git")
|
Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git")
|
||||||
|
|
||||||
|
Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git")
|
||||||
|
|
||||||
# Pkg.clone("https://github.com/JunoLab/Blink.jl.git")
|
# Pkg.clone("https://github.com/JunoLab/Blink.jl.git")
|
||||||
# Pkg.build("Blink")
|
# Pkg.build("Blink")
|
||||||
# import Blink
|
# import Blink
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user