Merge pull request #3056 from daschw/transpose_z

Remove `transpose_z` and simplify integration of Surfaces in backends
This commit is contained in:
Daniel Schwabeneder 2020-10-12 22:21:10 +02:00 committed by GitHub
commit c15483d593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 25 additions and 66 deletions

View File

@ -226,7 +226,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -315,7 +315,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -291,7 +291,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -227,7 +227,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -285,7 +285,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -285,7 +285,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -226,7 +226,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -317,7 +317,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -286,7 +286,6 @@ function _precompile_()
Base.precompile(Tuple{typeof(Plots.slice_arg),Array{Symbol,2},Int64})
Base.precompile(Tuple{typeof(Plots.slice_arg),Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}},Int64})
Base.precompile(Tuple{typeof(Plots.straightline_data),Tuple{Float64,Float64},Tuple{Float64,Float64},Array{Float64,1},Array{Float64,1},Int64})
Base.precompile(Tuple{typeof(Plots.transpose_z),Plots.Series,Array{Float64,2},Bool})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{Complex{Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{GeometryBasics.Point{2,Float64},1}})
Base.precompile(Tuple{typeof(RecipesBase.apply_recipe),Dict{Symbol,Any},Array{OHLC,1}})

View File

@ -280,8 +280,6 @@ const _series_defaults = KW(
:show_empty_bins => false, # should empty bins in 2D histogram be colored as zero (otherwise they are transparent)
:contours => false, # add contours to 3d surface and wireframe plots
:contour_labels => false,
:match_dimensions => false, # do rows match x (true) or y (false) for heatmap/image/spy? see issue 196
# this ONLY effects whether or not the z-matrix is transposed for a heatmap display!
:subplot => :auto, # which subplot(s) does this series belong to?
:series_annotations => nothing, # a list of annotations which apply to the coordinates of this series
:primary => true, # when true, this "counts" as a series for color selection, etc. the main use is to allow
@ -629,7 +627,6 @@ add_aliases(:quiver, :velocity, :quiver2d, :gradient, :vectorfield)
add_aliases(:normalize, :norm, :normed, :normalized)
add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty)
add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio)
add_aliases(:match_dimensions, :transpose, :transpose_z)
add_aliases(:subplot, :sp, :subplt, :splt)
add_aliases(:projection, :proj)
add_aliases(:titlelocation, :title_location, :title_loc, :titleloc, :title_position, :title_pos, :titlepos, :titleposition, :title_align, :title_alignment)

View File

@ -316,7 +316,6 @@ const _gr_attr = merge_with_base_supported([
:layout,
:title, :window_title,
:guide, :lims, :ticks, :scale, :flip,
:match_dimensions,
:titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontrotation, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign,
@ -472,7 +471,6 @@ const _pgfplots_attr = merge_with_base_supported([
:polar,
# :normalize, :weights, :contours,
:aspect_ratio,
# :match_dimensions,
:tick_direction,
:framestyle,
:camera,
@ -541,7 +539,6 @@ const _pyplot_attr = merge_with_base_supported([
:polar,
:normalize, :weights,
:contours, :aspect_ratio,
:match_dimensions,
:clims,
:inset_subplots,
:dpi,
@ -627,7 +624,6 @@ const _hdf5_attr = merge_with_base_supported([
:polar,
:normalize, :weights,
:contours, :aspect_ratio,
:match_dimensions,
:clims,
:inset_subplots,
:dpi,
@ -700,7 +696,6 @@ const _inspectdr_attr = merge_with_base_supported([
:polar,
# :normalize, :weights,
# :contours, :aspect_ratio,
:match_dimensions,
# :clims,
# :inset_subplots,
:dpi,
@ -761,7 +756,6 @@ const _pgfplotsx_attr = merge_with_base_supported([
:ticks,
:scale,
:flip,
:match_dimensions,
:titlefontfamily,
:titlefontsize,
:titlefonthalign,

View File

@ -1488,14 +1488,12 @@ function gr_add_series(sp, series)
GR.savestate()
x, y, z = series[:x], series[:y], series[:z]
x, y, z = (handle_surface(series[letter]) for letter in (:x, :y, :z))
xscale, yscale = sp[:xaxis][:scale], sp[:yaxis][:scale]
frng = series[:fillrange]
# recompute data
if typeof(z) <: Surface
z = transpose_z(series, z.surf, false)
elseif ispolar(sp)
if ispolar(sp)
rmin, rmax = axis_limits(sp, :y)
if frng !== nothing
_, frng = convert_to_polar(x, frng, (rmin, rmax))
@ -1752,7 +1750,6 @@ function gr_draw_heatmap(series, x, y, z, clims)
end
function gr_draw_image(series, x, y, z, clims)
z = transpose_z(series, series[:z].surf, true)'
w, h = size(z)
xmin, xmax = ignorenan_extrema(x)
ymin, ymax = ignorenan_extrema(y)

View File

@ -646,7 +646,7 @@ pgfx_series_arguments(series, opt, range) = (arg[range] for arg in pgfx_series_a
function pgfx_series_arguments(series, opt)
st = series[:seriestype]
return if st in (:contour, :contour3d)
opt[:x], opt[:y], Array(opt[:z])'
opt[:x], opt[:y], handle_surface(opt[:z])
elseif st in (:heatmap, :surface, :wireframe)
surface_to_vecs(opt[:x], opt[:y], opt[:z])
elseif RecipesPipeline.is3d(st)

View File

@ -459,7 +459,7 @@ function plotly_data(series::Series, letter::Symbol, data)
end
if series[:seriestype] in (:heatmap, :contour, :surface, :wireframe, :mesh3d)
plotly_surface_data(series, data)
handle_surface(data)
else
plotly_data(data)
end
@ -469,10 +469,6 @@ plotly_data(v::AbstractArray) = v
plotly_data(surf::Surface) = surf.surf
plotly_data(v::AbstractArray{R}) where {R<:Rational} = float(v)
plotly_surface_data(series::Series, a::AbstractVector) = a
plotly_surface_data(series::Series, a::AbstractMatrix) = transpose_z(series, a, false)
plotly_surface_data(series::Series, a::Surface) = plotly_surface_data(series, a.surf)
function plotly_native_data(axis::Axis, data::AbstractArray)
if !isempty(axis[:discrete_values])
construct_categorical_data(data, axis)
@ -588,7 +584,7 @@ function plotly_series(plt::Plot, series::Series)
plotattributes_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha])
plotattributes_out[:opacity] = series[:fillalpha]
if series[:fill_z] !== nothing
plotattributes_out[:surfacecolor] = plotly_surface_data(series, series[:fill_z])
plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z])
end
plotattributes_out[:showscale] = hascolorbar(sp)
end
@ -613,7 +609,7 @@ function plotly_series(plt::Plot, series::Series)
plotattributes_out[:color] = rgba_string(plot_color(series[:fillcolor], series[:fillalpha]))
plotattributes_out[:opacity] = series[:fillalpha]
if series[:fill_z] !== nothing
plotattributes_out[:surfacecolor] = plotly_surface_data(series, series[:fill_z])
plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z])
end
plotattributes_out[:showscale] = hascolorbar(sp)
else

View File

@ -344,7 +344,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
fix_xy_lengths!(plt, series)
# ax = getAxis(plt, series)
x, y, z = series[:x], series[:y], series[:z]
x, y, z = (Array(series[letter]) for letter in (:x, :y, :z))
if st == :straightline
x, y = straightline_data(series)
elseif st == :shape
@ -512,16 +512,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end
if st in (:contour, :contour3d)
z = transpose_z(series, z.surf)
if typeof(x)<:Plots.Surface
x = Plots.transpose_z(series, x.surf)
end
if typeof(y)<:Plots.Surface
y = Plots.transpose_z(series, y.surf)
end
if st == :contour3d
extrakw[:extend3d] = true
if !ismatrix(x) || !ismatrix(y)
x, y = repeat(x', length(y), 1), repeat(y, 1, length(x))
end
end
if typeof(series[:linecolor]) <: AbstractArray
@ -556,17 +551,17 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end
if st in (:surface, :wireframe)
if typeof(z) <: AbstractMatrix || typeof(z) <: Surface
x, y, z = map(Array, (x,y,z))
if z isa AbstractMatrix
if !ismatrix(x) || !ismatrix(y)
x = repeat(x', length(y), 1)
y = repeat(y, 1, length(series[:x]))
x, y = repeat(x', length(y), 1), repeat(y, 1, length(x))
end
z = transpose_z(series, z)
if st == :surface
if series[:fill_z] !== nothing
# the surface colors are different than z-value
extrakw[:facecolors] = py_shading(series[:fillcolor], transpose_z(series, series[:fill_z].surf))
extrakw[:facecolors] = py_shading(
series[:fillcolor],
Array(series[:fill_z]),
)
extrakw[:shade] = false
else
extrakw[:cmap] = py_fillcolormap(series)
@ -618,15 +613,15 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
ymin, ymax = ignorenan_extrema(series[:y])
dx = (xmax - xmin) / (length(series[:x]) - 1) / 2
dy = (ymax - ymin) / (length(series[:y]) - 1) / 2
img = Array(transpose_z(series, z.surf))
z = if eltype(img) <: Colors.AbstractGray
float(img)
z = if eltype(z) <: Colors.AbstractGray
float(z)
elseif eltype(img) <: Colorant
map(c -> Float64[red(c),green(c),blue(c),alpha(c)], img)
map(c -> Float64[red(c),green(c),blue(c),alpha(c)], z)
else
z # hopefully it's in a data format that will "just work" with imshow
end
handle = ax."imshow"(z;
handle = ax."imshow"(
z;
zorder = series[:series_plotindex],
cmap = py_colormap(cgrad(plot_color([:black, :white]))),
vmin = 0.0,
@ -642,7 +637,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end
if st == :heatmap
x, y, z = heatmap_edges(x, sp[:xaxis][:scale]), heatmap_edges(y, sp[:yaxis][:scale]), transpose_z(series, z.surf)
x, y = heatmap_edges(x, sp[:xaxis][:scale], y, sp[:yaxis][:scale], size(z))
expand_extrema!(sp[:xaxis], x)
expand_extrema!(sp[:yaxis], y)

View File

@ -874,9 +874,7 @@ end
x := Plots._bin_centers(edge_x)
y := Plots._bin_centers(edge_y)
z := Surface(float_weights)
match_dimensions := true
z := Surface(permutedims(float_weights))
seriestype := :heatmap
()
end

View File

@ -334,17 +334,8 @@ function indices_and_unique_values(z::AbstractArray)
newz, vals
end
# 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
# for example: PyPlot sends rows to y, so transpose_on_match should be true
function transpose_z(plotattributes, z, transpose_on_match::Bool = true)
if plotattributes[:match_dimensions] == transpose_on_match
# z'
permutedims(z, [2,1])
else
z
end
end
handle_surface(z) = z
handle_surface(z::Surface) = permutedims(z.surf)
function ok(x::Number, y::Number, z::Number = 0)
isfinite(x) && isfinite(y) && isfinite(z)