Merge pull request #2427 from daschw/ratio

use equal aspect ratio by default for images
This commit is contained in:
Daniel Schwabeneder 2020-03-01 08:52:41 +01:00 committed by GitHub
commit 16b8d01b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 19 deletions

View File

@ -1,7 +1,7 @@
name = "Plots" name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"] author = ["Tom Breloff (@tbreloff)"]
version = "0.29.3" version = "0.29.4"
[deps] [deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

View File

@ -345,7 +345,7 @@ const _subplot_defaults = KW(
:legendtitlefontcolor => :match, :legendtitlefontcolor => :match,
:annotations => [], # annotation tuples... list of (x,y,annotation) :annotations => [], # annotation tuples... list of (x,y,annotation)
:projection => :none, # can also be :polar or :3d :projection => :none, # can also be :polar or :3d
:aspect_ratio => :none, # choose from :none or :equal :aspect_ratio => :auto, # choose from :none or :equal
:margin => 1mm, :margin => 1mm,
:left_margin => :match, :left_margin => :match,
:top_margin => :match, :top_margin => :match,

View File

@ -981,7 +981,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
data_lims = gr_xy_axislims(sp) data_lims = gr_xy_axislims(sp)
xy_lims = data_lims xy_lims = data_lims
ratio = sp[:aspect_ratio] ratio = get_aspect_ratio(sp)
if ratio != :none if ratio != :none
if ratio == :equal if ratio == :equal
ratio = 1 ratio = 1

View File

@ -470,7 +470,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", sp[:titlefontrotation], "}")) push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", sp[:titlefontrotation], "}"))
end end
if sp[:aspect_ratio] in (1, :equal) if get_aspect_ratio(sp) in (1, :equal)
kw[:axisEqual] = "true" kw[:axisEqual] = "true"
end end

View File

@ -108,7 +108,7 @@ function shrink_by(lo, sz, ratio)
end end
function plotly_apply_aspect_ratio(sp::Subplot, plotarea, pcts) function plotly_apply_aspect_ratio(sp::Subplot, plotarea, pcts)
aspect_ratio = sp[:aspect_ratio] aspect_ratio = get_aspect_ratio(sp)
if aspect_ratio != :none if aspect_ratio != :none
if aspect_ratio == :equal if aspect_ratio == :equal
aspect_ratio = 1.0 aspect_ratio = 1.0

View File

@ -1155,7 +1155,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
end end
# aspect ratio # aspect ratio
aratio = sp[:aspect_ratio] aratio = get_aspect_ratio(sp)
if aratio != :none if aratio != :none
ax."set_aspect"(isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C") ax."set_aspect"(isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C")
end end

View File

@ -347,6 +347,7 @@ end
seriestype := :heatmap seriestype := :heatmap
yflip --> true yflip --> true
cbar --> false cbar --> false
aspect_ratio --> :equal
z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat)
SliceIt, m, n, Surface(z) SliceIt, m, n, Surface(z)
end end

View File

@ -116,24 +116,11 @@ end
function replace_image_with_heatmap(z::Array{T}) where T<:Colorant function replace_image_with_heatmap(z::Array{T}) where T<:Colorant
n, m = size(z) n, m = size(z)
# idx = 0
colors = ColorGradient(vec(z)) colors = ColorGradient(vec(z))
newz = reshape(range(0, stop=1, length=n*m), n, m) newz = reshape(range(0, stop=1, length=n*m), n, m)
newz, colors newz, colors
# newz = zeros(n, m)
# for i=1:n, j=1:m
# push!(colors, T(z[i,j]...))
# newz[i,j] = idx / (n*m-1)
# idx += 1
# end
# newz, ColorGradient(colors)
end end
function imageHack(plotattributes::AKW)
is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!")
plotattributes[:seriestype] = :heatmap
plotattributes[:z], plotattributes[:fillcolor] = replace_image_with_heatmap(plotattributes[:z].surf)
end
# --------------------------------------------------------------- # ---------------------------------------------------------------
"Build line segments for plotting" "Build line segments for plotting"
@ -710,6 +697,19 @@ function has_attribute_segments(series::Series)
return any((typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1) for attr in [:seriescolor, :seriesalpha, :linecolor, :linealpha, :linewidth, :linestyle, :fillcolor, :fillalpha, :markercolor, :markeralpha, :markerstrokecolor, :markerstrokealpha]) || any(typeof(series[attr]) <: AbstractArray for attr in (:line_z, :fill_z, :marker_z)) return any((typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1) for attr in [:seriescolor, :seriesalpha, :linecolor, :linealpha, :linewidth, :linestyle, :fillcolor, :fillalpha, :markercolor, :markeralpha, :markerstrokecolor, :markerstrokealpha]) || any(typeof(series[attr]) <: AbstractArray for attr in (:line_z, :fill_z, :marker_z))
end end
function get_aspect_ratio(sp)
aspect_ratio = sp[:aspect_ratio]
if aspect_ratio == :auto
aspect_ratio = :none
for series in series_list(sp)
if series[:seriestype] == :image
aspect_ratio = :equal
end
end
end
return aspect_ratio
end
# --------------------------------------------------------------- # ---------------------------------------------------------------
makekw(; kw...) = KW(kw) makekw(; kw...) = KW(kw)

View File

@ -44,6 +44,30 @@ default(show=false, reuse=true)
is_ci() = get(ENV, "CI", "false") == "true" is_ci() = get(ENV, "CI", "false") == "true"
img_tol = is_ci() ? 1e-2 : 1e-3 img_tol = is_ci() ? 1e-2 : 1e-3
## Uncomment the following lines to update reference images for different backends
#=
@testset "GR" begin
image_comparison_facts(:gr, tol=img_tol, skip = Plots._backend_skips[:gr])
end
plotly()
@testset "Plotly" begin
image_comparison_facts(:plotly, tol=img_tol, skip = Plots._backend_skips[:plotlyjs])
end
pyplot()
@testset "PyPlot" begin
image_comparison_facts(:pyplot, tol=img_tol, skip = Plots._backend_skips[:pyplot])
end
pgfplots()
@testset "PGFPlots" begin
image_comparison_facts(:pgfplots, tol=img_tol, skip = Plots._backend_skips[:pgfplots])
end
=#
##
@testset "Backends" begin @testset "Backends" begin
@testset "GR" begin @testset "GR" begin