remove transpose_z

This commit is contained in:
Daniel Schwabeneder 2020-10-12 01:10:56 +02:00
parent 2ef13c19ea
commit 9cf9edffe0
8 changed files with 25 additions and 46 deletions

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) :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 :contours => false, # add contours to 3d surface and wireframe plots
:contour_labels => false, :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? :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 :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 :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(:normalize, :norm, :normed, :normalized)
add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty) add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty)
add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio) add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio)
add_aliases(:match_dimensions, :transpose, :transpose_z)
add_aliases(:subplot, :sp, :subplt, :splt) add_aliases(:subplot, :sp, :subplt, :splt)
add_aliases(:projection, :proj) add_aliases(:projection, :proj)
add_aliases(:titlelocation, :title_location, :title_loc, :titleloc, :title_position, :title_pos, :titlepos, :titleposition, :title_align, :title_alignment) 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, :layout,
:title, :window_title, :title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :guide, :lims, :ticks, :scale, :flip,
:match_dimensions,
:titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign, :titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontrotation, :titlefontcolor, :titlefontrotation, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign, :legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign,
@ -472,7 +471,6 @@ const _pgfplots_attr = merge_with_base_supported([
:polar, :polar,
# :normalize, :weights, :contours, # :normalize, :weights, :contours,
:aspect_ratio, :aspect_ratio,
# :match_dimensions,
:tick_direction, :tick_direction,
:framestyle, :framestyle,
:camera, :camera,
@ -541,7 +539,6 @@ const _pyplot_attr = merge_with_base_supported([
:polar, :polar,
:normalize, :weights, :normalize, :weights,
:contours, :aspect_ratio, :contours, :aspect_ratio,
:match_dimensions,
:clims, :clims,
:inset_subplots, :inset_subplots,
:dpi, :dpi,
@ -627,7 +624,6 @@ const _hdf5_attr = merge_with_base_supported([
:polar, :polar,
:normalize, :weights, :normalize, :weights,
:contours, :aspect_ratio, :contours, :aspect_ratio,
:match_dimensions,
:clims, :clims,
:inset_subplots, :inset_subplots,
:dpi, :dpi,
@ -700,7 +696,6 @@ const _inspectdr_attr = merge_with_base_supported([
:polar, :polar,
# :normalize, :weights, # :normalize, :weights,
# :contours, :aspect_ratio, # :contours, :aspect_ratio,
:match_dimensions,
# :clims, # :clims,
# :inset_subplots, # :inset_subplots,
:dpi, :dpi,
@ -761,7 +756,6 @@ const _pgfplotsx_attr = merge_with_base_supported([
:ticks, :ticks,
:scale, :scale,
:flip, :flip,
:match_dimensions,
:titlefontfamily, :titlefontfamily,
:titlefontsize, :titlefontsize,
:titlefonthalign, :titlefonthalign,

View File

@ -1488,14 +1488,12 @@ function gr_add_series(sp, series)
GR.savestate() 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] xscale, yscale = sp[:xaxis][:scale], sp[:yaxis][:scale]
frng = series[:fillrange] frng = series[:fillrange]
# recompute data # recompute data
if typeof(z) <: Surface if ispolar(sp)
z = transpose_z(series, z.surf, false)
elseif ispolar(sp)
rmin, rmax = axis_limits(sp, :y) rmin, rmax = axis_limits(sp, :y)
if frng !== nothing if frng !== nothing
_, frng = convert_to_polar(x, frng, (rmin, rmax)) _, frng = convert_to_polar(x, frng, (rmin, rmax))
@ -1752,7 +1750,6 @@ function gr_draw_heatmap(series, x, y, z, clims)
end end
function gr_draw_image(series, x, y, z, clims) function gr_draw_image(series, x, y, z, clims)
z = transpose_z(series, series[:z].surf, true)'
w, h = size(z) w, h = size(z)
xmin, xmax = ignorenan_extrema(x) xmin, xmax = ignorenan_extrema(x)
ymin, ymax = ignorenan_extrema(y) 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) function pgfx_series_arguments(series, opt)
st = series[:seriestype] st = series[:seriestype]
return if st in (:contour, :contour3d) 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) elseif st in (:heatmap, :surface, :wireframe)
surface_to_vecs(opt[:x], opt[:y], opt[:z]) surface_to_vecs(opt[:x], opt[:y], opt[:z])
elseif RecipesPipeline.is3d(st) elseif RecipesPipeline.is3d(st)

View File

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

View File

@ -344,7 +344,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
fix_xy_lengths!(plt, series) fix_xy_lengths!(plt, series)
# ax = getAxis(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 if st == :straightline
x, y = straightline_data(series) x, y = straightline_data(series)
elseif st == :shape elseif st == :shape
@ -512,16 +512,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
if st in (:contour, :contour3d) 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 if st == :contour3d
extrakw[:extend3d] = true extrakw[:extend3d] = true
if !ismatrix(x) || !ismatrix(y)
x, y = repeat(x', length(y), 1), repeat(y, 1, length(x))
end
end end
if typeof(series[:linecolor]) <: AbstractArray if typeof(series[:linecolor]) <: AbstractArray
@ -556,17 +551,17 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
if st in (:surface, :wireframe) if st in (:surface, :wireframe)
if typeof(z) <: AbstractMatrix || typeof(z) <: Surface if z isa AbstractMatrix
x, y, z = map(Array, (x,y,z))
if !ismatrix(x) || !ismatrix(y) if !ismatrix(x) || !ismatrix(y)
x = repeat(x', length(y), 1) x, y = repeat(x', length(y), 1), repeat(y, 1, length(x))
y = repeat(y, 1, length(series[:x]))
end end
z = transpose_z(series, z)
if st == :surface if st == :surface
if series[:fill_z] !== nothing if series[:fill_z] !== nothing
# the surface colors are different than z-value # 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 extrakw[:shade] = false
else else
extrakw[:cmap] = py_fillcolormap(series) extrakw[:cmap] = py_fillcolormap(series)
@ -618,15 +613,15 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
ymin, ymax = ignorenan_extrema(series[:y]) ymin, ymax = ignorenan_extrema(series[:y])
dx = (xmax - xmin) / (length(series[:x]) - 1) / 2 dx = (xmax - xmin) / (length(series[:x]) - 1) / 2
dy = (ymax - ymin) / (length(series[:y]) - 1) / 2 dy = (ymax - ymin) / (length(series[:y]) - 1) / 2
img = Array(transpose_z(series, z.surf)) z = if eltype(z) <: Colors.AbstractGray
z = if eltype(img) <: Colors.AbstractGray float(z)
float(img)
elseif eltype(img) <: Colorant 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 else
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 = series[:series_plotindex], zorder = series[:series_plotindex],
cmap = py_colormap(cgrad(plot_color([:black, :white]))), cmap = py_colormap(cgrad(plot_color([:black, :white]))),
vmin = 0.0, vmin = 0.0,
@ -642,7 +637,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
if st == :heatmap 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[:xaxis], x)
expand_extrema!(sp[:yaxis], y) expand_extrema!(sp[:yaxis], y)

View File

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

View File

@ -345,6 +345,8 @@ function transpose_z(plotattributes, z, transpose_on_match::Bool = true)
z z
end end
end end
handle_surface(z) = z
handle_surface(z::Surface) = permutedims(z.surf)
function ok(x::Number, y::Number, z::Number = 0) function ok(x::Number, y::Number, z::Number = 0)
isfinite(x) && isfinite(y) && isfinite(z) isfinite(x) && isfinite(y) && isfinite(z)