Merge pull request #3142 from daschw/gr-image

Fix plotting images with custom axes in GR
This commit is contained in:
Daniel Schwabeneder 2020-11-12 15:08:22 +01:00 committed by GitHub
commit e7212961dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View File

@ -68,8 +68,9 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
[targets] [targets]
test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"] test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"]

View File

@ -1578,17 +1578,15 @@ function gr_add_series(sp, series)
sp[:legend] = :none sp[:legend] = :none
GR.gr3.clear() GR.gr3.clear()
dmin, dmax = GR.gr3.volume(y.v, 0) dmin, dmax = GR.gr3.volume(y.v, 0)
elseif st in (:heatmap, :image) elseif st === :heatmap
if !ispolar(series) if !ispolar(series)
# `z` is already transposed, so we need to reverse before passing its size. # `z` is already transposed, so we need to reverse before passing its size.
x, y = heatmap_edges(x, xscale, y, yscale, reverse(size(z))) x, y = heatmap_edges(x, xscale, y, yscale, reverse(size(z)))
end end
if st === :heatmap
gr_draw_heatmap(series, x, y, z, clims) gr_draw_heatmap(series, x, y, z, clims)
else elseif st === :image
gr_draw_image(series, x, y, z, clims) gr_draw_image(series, x, y, z, clims)
end end
end
# this is all we need to add the series_annotations text # this is all we need to add the series_annotations text
anns = series[:series_annotations] anns = series[:series_annotations]

View File

@ -1067,6 +1067,20 @@ const _examples = PlotExample[
) )
end] end]
), ),
PlotExample( # 51
"Images with custom axes",
"",
[quote
using Plots
using TestImages
img = testimage("lighthouse")
# plot the image reversing the first dimension and setting yflip = false
plot([-π, π], [-1, 1], reverse(img, dims=1), yflip=false, aspect_ratio=:none)
# plot other data
plot!(sin, -π, π, lw=3, color=:red)
end]
),
] ]
# Some constants for PlotDocs and PlotReferenceImages # Some constants for PlotDocs and PlotReferenceImages
@ -1074,8 +1088,8 @@ _animation_examples = [2, 31]
_backend_skips = Dict( _backend_skips = Dict(
:gr => [25, 30, 47], :gr => [25, 30, 47],
:pyplot => [2, 25, 30, 31, 47, 49], :pyplot => [2, 25, 30, 31, 47, 49],
:plotlyjs => [2, 21, 24, 25, 30, 31, 49], :plotlyjs => [2, 21, 24, 25, 30, 31, 49, 51],
:plotly => [2, 21, 24, 25, 30, 31, 49], :plotly => [2, 21, 24, 25, 30, 31, 49, 51],
:pgfplotsx => [ :pgfplotsx => [
2, # animation 2, # animation
6, # images 6, # images
@ -1084,6 +1098,7 @@ _backend_skips = Dict(
31, # animation 31, # animation
32, # spy 32, # spy
49, # polar heatmap 49, # polar heatmap
51, # image with custom axes
], ],
) )

View File

@ -4,6 +4,7 @@ using Plots
using Random using Random
using StableRNGs using StableRNGs
using Test using Test
using TestImages
using FileIO using FileIO
using Gtk using Gtk
using LibGit2 using LibGit2