image fixes and support in pyplot
This commit is contained in:
parent
7bee9a5829
commit
a1b991aaeb
@ -40,13 +40,14 @@ supportedTypes(::PyPlotBackend) = [
|
||||
:none, :line, :path, :steppre, :steppost, :shape,
|
||||
:scatter, :hist2d, :hexbin, :hist, :density,
|
||||
:bar, :sticks, :box, :violin, :quiver,
|
||||
:hline, :vline, :heatmap, :pie,
|
||||
:hline, :vline, :heatmap, :pie, :image,
|
||||
:contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
|
||||
]
|
||||
supportedStyles(::PyPlotBackend) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||
supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape)
|
||||
supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10]
|
||||
subplotSupported(::PyPlotBackend) = true
|
||||
nativeImagesSupported(::PyPlotBackend) = true
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------
|
||||
@ -627,6 +628,21 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
|
||||
end
|
||||
end
|
||||
|
||||
if lt == :image
|
||||
img = Array(transpose_z(d, z.surf))
|
||||
z = if eltype(img) <: Colors.AbstractGray
|
||||
float(img)
|
||||
elseif eltype(img) <: Colorant
|
||||
map(c -> Float64[red(c),green(c),blue(c)], img)
|
||||
else
|
||||
z # hopefully it's in a data format that will "just work" with imshow
|
||||
end
|
||||
handle = ax[:imshow](z;
|
||||
zorder = plt.n
|
||||
)
|
||||
push!(handles, handle)
|
||||
end
|
||||
|
||||
if lt == :heatmap
|
||||
x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(d, z.surf)
|
||||
if !(eltype(z) <: Number)
|
||||
@ -1030,7 +1046,7 @@ function addPyPlotLegend(plt::Plot, ax)
|
||||
args = filter(x -> !(x[:linetype] in (
|
||||
:hist,:density,:hexbin,:hist2d,:hline,:vline,
|
||||
:contour,:contour3d,:surface,:wireframe,
|
||||
:heatmap,:path3d,:scatter3d, :pie
|
||||
:heatmap,:path3d,:scatter3d, :pie, :image
|
||||
)), plt.seriesargs)
|
||||
args = filter(x -> x[:label] != "", args)
|
||||
if length(args) > 0
|
||||
|
||||
@ -249,13 +249,13 @@ end
|
||||
# images - grays
|
||||
function process_inputs{T<:Gray}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
||||
d[:linetype] = :image
|
||||
d[:yflip] = true
|
||||
n,m = size(mat)
|
||||
d[:x], d[:y], d[:z] = 1:n, 1:m, mat
|
||||
d[:x], d[:y], d[:z] = 1:n, 1:m, Surface(mat)
|
||||
# handle images... when not supported natively, do a hack to use heatmap machinery
|
||||
if !nativeImagesSupported()
|
||||
d[:linetype] = :heatmap
|
||||
d[:z] = convert(Matrix{Float64}, mat)
|
||||
d[:yflip] = true
|
||||
d[:z] = Surface(convert(Matrix{Float64}, mat.surf))
|
||||
d[:fillcolor] = ColorGradient([:black, :white])
|
||||
end
|
||||
end
|
||||
@ -263,11 +263,11 @@ end
|
||||
# images - colors
|
||||
function process_inputs{T<:Colorant}(plt::AbstractPlot, d::KW, mat::AMat{T})
|
||||
d[:linetype] = :image
|
||||
d[:yflip] = true
|
||||
n,m = size(mat)
|
||||
d[:x], d[:y], d[:z] = 1:n, 1:m, mat
|
||||
d[:x], d[:y], d[:z] = 1:n, 1:m, Surface(mat)
|
||||
# handle images... when not supported natively, do a hack to use heatmap machinery
|
||||
if !nativeImagesSupported()
|
||||
d[:yflip] = true
|
||||
imageHack(d)
|
||||
end
|
||||
end
|
||||
|
||||
@ -133,7 +133,7 @@ end
|
||||
function imageHack(d::KW)
|
||||
:heatmap in supportedTypes() || error("Neither :image or :heatmap are supported!")
|
||||
d[:linetype] = :heatmap
|
||||
d[:z], d[:fillcolor] = replace_image_with_heatmap(d[:z])
|
||||
d[:z], d[:fillcolor] = replace_image_with_heatmap(d[:z].surf)
|
||||
end
|
||||
# ---------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user