fixes for images/heatmaps/surfaces
This commit is contained in:
parent
f91c4d586c
commit
f33905ed80
15
src/axes.jl
15
src/axes.jl
@ -169,6 +169,21 @@ function discrete_value!(a::Axis, v::AVec)
|
|||||||
cvec, discrete_indices
|
cvec, discrete_indices
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add the discrete value for each item. return the continuous values and the indices
|
||||||
|
function discrete_value!(a::Axis, v::AMat)
|
||||||
|
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!(a, v[i,j])
|
||||||
|
end
|
||||||
|
cmat, discrete_indices
|
||||||
|
end
|
||||||
|
|
||||||
|
function discrete_value!(a::Axis, v::Surface)
|
||||||
|
map(Surface, discrete_value!(a, v.surf))
|
||||||
|
end
|
||||||
|
|
||||||
function pie_labels(sp::Subplot, series::Series)
|
function pie_labels(sp::Subplot, series::Series)
|
||||||
d = series.d
|
d = series.d
|
||||||
if haskey(d,:x_discrete_indices)
|
if haskey(d,:x_discrete_indices)
|
||||||
|
|||||||
@ -714,6 +714,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if st == :image
|
if st == :image
|
||||||
|
# @show typeof(z)
|
||||||
img = Array(transpose_z(d, z.surf))
|
img = Array(transpose_z(d, z.surf))
|
||||||
z = if eltype(img) <: Colors.AbstractGray
|
z = if eltype(img) <: Colors.AbstractGray
|
||||||
float(img)
|
float(img)
|
||||||
@ -723,15 +724,22 @@ function _series_added(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 = plt.n
|
zorder = plt.n,
|
||||||
|
cmap = getPyPlotColorMap([:black, :white]),
|
||||||
|
vmin = 0.0,
|
||||||
|
vmax = 1.0
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
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(d, 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
|
||||||
|
dvals = sp.attr[:zaxis][:discrete_values]
|
||||||
|
if !isempty(dvals)
|
||||||
|
discrete_colorbar_values = dvals
|
||||||
end
|
end
|
||||||
handle = ax[:pcolormesh](x, y, z;
|
handle = ax[:pcolormesh](x, y, z;
|
||||||
label = d[:label],
|
label = d[:label],
|
||||||
@ -784,7 +792,8 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
kw = KW()
|
kw = KW()
|
||||||
if discrete_colorbar_values != nothing
|
if discrete_colorbar_values != nothing
|
||||||
locator, formatter = get_locator_and_formatter(discrete_colorbar_values)
|
locator, formatter = get_locator_and_formatter(discrete_colorbar_values)
|
||||||
kw[:values] = 1:length(discrete_colorbar_values)
|
# kw[:values] = 1:length(discrete_colorbar_values)
|
||||||
|
kw[:values] = sp.attr[:zaxis][:continuous_values]
|
||||||
kw[:ticks] = locator
|
kw[:ticks] = locator
|
||||||
kw[:format] = formatter
|
kw[:format] = formatter
|
||||||
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
||||||
@ -794,7 +803,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# note: the colorbar axis is positioned independently from the subplot axis
|
# note: the colorbar axis is positioned independently from the subplot axis
|
||||||
fig = plt.o
|
fig = plt.o
|
||||||
cbax = fig[:add_axes]([0.8,0.1,0.03,0.8])
|
cbax = fig[:add_axes]([0.8,0.1,0.03,0.8])
|
||||||
sp.attr[:cbar_handle] = fig[:colorbar](handle, cax = cbax, kw...)
|
sp.attr[:cbar_handle] = fig[:colorbar](handle; cax = cbax, kw...)
|
||||||
sp.attr[:cbar_ax] = cbax
|
sp.attr[:cbar_ax] = cbax
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
28
src/plot.jl
28
src/plot.jl
@ -43,7 +43,7 @@ When you pass in matrices, it splits by columns. See the documentation for more
|
|||||||
|
|
||||||
# this creates a new plot with args/kw and sets it to be the current plot
|
# this creates a new plot with args/kw and sets it to be the current plot
|
||||||
function plot(args...; kw...)
|
function plot(args...; kw...)
|
||||||
pkg = backend()
|
# pkg = backend()
|
||||||
d = KW(kw)
|
d = KW(kw)
|
||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
|
|
||||||
@ -116,17 +116,21 @@ function _apply_series_recipe(plt::Plot, d::KW)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# adjust extrema and discrete info
|
# adjust extrema and discrete info
|
||||||
for letter in (:x, :y, :z)
|
if st != :image
|
||||||
data = d[letter]
|
for letter in (:x, :y, :z)
|
||||||
axis = sp.attr[symbol(letter, "axis")]
|
data = d[letter]
|
||||||
if eltype(data) <: Number
|
axis = sp.attr[symbol(letter, "axis")]
|
||||||
expand_extrema!(axis, data)
|
if eltype(data) <: Number
|
||||||
elseif data != nothing
|
expand_extrema!(axis, data)
|
||||||
# TODO: need more here... gotta track the discrete reference value
|
elseif isa(data, Surface) && eltype(data.surf) <: Number
|
||||||
# as well as any coord offset (think of boxplot shape coords... they all
|
expand_extrema!(axis, data)
|
||||||
# correspond to the same x-value)
|
elseif data != nothing
|
||||||
# @show letter,eltype(data),typeof(data)
|
# TODO: need more here... gotta track the discrete reference value
|
||||||
d[letter], d[symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
|
# as well as any coord offset (think of boxplot shape coords... they all
|
||||||
|
# correspond to the same x-value)
|
||||||
|
# @show letter,eltype(data),typeof(data)
|
||||||
|
d[letter], d[symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -148,7 +148,7 @@ end
|
|||||||
# function process_inputs{T<:Number}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
# function process_inputs{T<:Number}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
||||||
# if all3D(d)
|
# if all3D(d)
|
||||||
# n,m = size(mat)
|
# n,m = size(mat)
|
||||||
# d[:x], d[:y], d[:z] = 1:n, 1:m, mat
|
# d[:x], d[:y], d[:z] = 1:m, 1:n, mat
|
||||||
# else
|
# else
|
||||||
# d[:y] = mat
|
# d[:y] = mat
|
||||||
# end
|
# end
|
||||||
@ -158,9 +158,9 @@ end
|
|||||||
@recipe function f{T<:Number}(mat::AMat{T})
|
@recipe function f{T<:Number}(mat::AMat{T})
|
||||||
if all3D(d)
|
if all3D(d)
|
||||||
n,m = size(mat)
|
n,m = size(mat)
|
||||||
1:n, 1:m, Surface(mat)
|
SliceIt, 1:m, 1:n, Surface(mat)
|
||||||
else
|
else
|
||||||
nothing, mat, nothing
|
SliceIt, nothing, mat, nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ end
|
|||||||
# function process_inputs{T<:Gray}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
# function process_inputs{T<:Gray}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
||||||
# d[:seriestype] = :image
|
# d[:seriestype] = :image
|
||||||
# n,m = size(mat)
|
# n,m = size(mat)
|
||||||
# d[:x], d[:y], d[:z] = 1:n, 1:m, Surface(mat)
|
# d[:x], d[:y], d[:z] = 1:m, 1:n, Surface(mat)
|
||||||
# # handle images... when not supported natively, do a hack to use heatmap machinery
|
# # handle images... when not supported natively, do a hack to use heatmap machinery
|
||||||
# if !nativeImagesSupported()
|
# if !nativeImagesSupported()
|
||||||
# d[:seriestype] = :heatmap
|
# d[:seriestype] = :heatmap
|
||||||
@ -182,14 +182,14 @@ end
|
|||||||
|
|
||||||
@recipe function f{T<:Gray}(mat::AMat{T})
|
@recipe function f{T<:Gray}(mat::AMat{T})
|
||||||
if nativeImagesSupported()
|
if nativeImagesSupported()
|
||||||
seriestype --> :image, force
|
seriestype := :image
|
||||||
n, m = size(mat)
|
n, m = size(mat)
|
||||||
1:n, 1:m, Surface(mat)
|
SliceIt, 1:m, 1:n, Surface(mat)
|
||||||
else
|
else
|
||||||
seriestype --> :heatmap, force
|
seriestype := :heatmap
|
||||||
yflip --> true
|
yflip --> true
|
||||||
fillcolor --> ColorGradient([:black, :white])
|
fillcolor --> ColorGradient([:black, :white])
|
||||||
1:n, 1:m, Surface(convert(Matrix{Float64}, mat))
|
SliceIt, 1:m, 1:n, Surface(convert(Matrix{Float64}, mat))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ end
|
|||||||
# function process_inputs{T<:Colorant}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
# function process_inputs{T<:Colorant}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
||||||
# d[:seriestype] = :image
|
# d[:seriestype] = :image
|
||||||
# n,m = size(mat)
|
# n,m = size(mat)
|
||||||
# d[:x], d[:y], d[:z] = 1:n, 1:m, Surface(mat)
|
# d[:x], d[:y], d[:z] = 1:m, 1:n, Surface(mat)
|
||||||
# # handle images... when not supported natively, do a hack to use heatmap machinery
|
# # handle images... when not supported natively, do a hack to use heatmap machinery
|
||||||
# if !nativeImagesSupported()
|
# if !nativeImagesSupported()
|
||||||
# d[:yflip] = true
|
# d[:yflip] = true
|
||||||
@ -209,14 +209,14 @@ end
|
|||||||
|
|
||||||
@recipe function f{T<:Colorant}(mat::AMat{T})
|
@recipe function f{T<:Colorant}(mat::AMat{T})
|
||||||
if nativeImagesSupported()
|
if nativeImagesSupported()
|
||||||
seriestype --> :image, force
|
seriestype := :image
|
||||||
n, m = size(mat)
|
n, m = size(mat)
|
||||||
1:n, 1:m, Surface(mat)
|
SliceIt, 1:m, 1:n, Surface(mat)
|
||||||
else
|
else
|
||||||
seriestype --> :heatmap, force
|
seriestype := :heatmap
|
||||||
yflip --> true
|
yflip --> true
|
||||||
z, d[:fillcolor] = replace_image_with_heatmap(mat)
|
z, d[:fillcolor] = replace_image_with_heatmap(mat)
|
||||||
1:n, 1:m, Surface(z)
|
SliceIt, 1:m, 1:n, Surface(z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ end
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
@recipe function f(shape::Shape)
|
@recipe function f(shape::Shape)
|
||||||
seriestype --> :shape, force
|
seriestype := :shape
|
||||||
shape_coords(shape)
|
shape_coords(shape)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ end
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
@recipe function f(shapes::AVec{Shape})
|
@recipe function f(shapes::AVec{Shape})
|
||||||
seriestype --> :shape, force
|
seriestype := :shape
|
||||||
shape_coords(shapes)
|
shape_coords(shapes)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -312,12 +312,22 @@ end
|
|||||||
st = get(d, :seriestype, :none)
|
st = get(d, :seriestype, :none)
|
||||||
if st == :scatter
|
if st == :scatter
|
||||||
d[:seriestype] = :scatter3d
|
d[:seriestype] = :scatter3d
|
||||||
elseif !(st in _3dTypes)
|
elseif !is3d(st)
|
||||||
d[:seriestype] = :path3d
|
d[:seriestype] = :path3d
|
||||||
end
|
end
|
||||||
SliceIt, x, y, z
|
SliceIt, x, y, z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@recipe function f(x::AMat, y::AMat, z::AMat)
|
||||||
|
st = get(d, :seriestype, :none)
|
||||||
|
if size(x) == size(y) == size(z)
|
||||||
|
if !is3d(st)
|
||||||
|
seriestype := :path3d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
SliceIt, x, y, z
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# # surface-like... function
|
# # surface-like... function
|
||||||
# function process_inputs{TX,TY}(plt::AbstractPlot, d::KW, x::AVec{TX}, y::AVec{TY}, zf::Function)
|
# function process_inputs{TX,TY}(plt::AbstractPlot, d::KW, x::AVec{TX}, y::AVec{TY}, zf::Function)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user