Skip to content

Commit e82797c

Browse files
authored
plot Colorant rasters as images (#358)
1 parent 4a09859 commit e82797c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/plotrecipes.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@ end
7070
:aspect_ratio --> square_pixels
7171
end
7272

73-
if get(plotattributes, :seriestype, :none) == :contourf
73+
74+
if eltype(A) <: ColorTypes.Colorant
75+
index(x), index(y), parent(A)
76+
elseif get(plotattributes, :seriestype, :none) == :contourf
77+
A = replace_missing(A, missing)
7478
clims = extrema(skipmissing(A))
7579
:levels --> range(clims[1], clims[2], length=20)
7680
index(x), index(y), clamp.(A, clims[1], clims[2])
7781
else
7882
:seriestype --> :heatmap
83+
A = replace_missing(A, missing)
7984
index(x), index(y), parent(A)
8085
end
8186
end
@@ -193,8 +198,7 @@ _prepare(d::Dimension) = d |> _maybe_shift |> _maybe_mapped
193198
# Convert arrays to a consistent missing value and Forward array order
194199
function _prepare(A::AbstractRaster)
195200
reorder(A, DD.ForwardOrdered) |>
196-
a -> permutedims(a, DD.commondims(>:, (ZDim, YDim, XDim, TimeDim, Dimension), dims(A))) |>
197-
a -> replace_missing(a, missing)
201+
a -> permutedims(a, DD.commondims(>:, (ZDim, YDim, XDim, TimeDim, Dimension), dims(A)))# |>
198202
end
199203

200204
function _subsample(A, max_res)

test/plotrecipes.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Rasters, Test, Dates, Plots
1+
using Rasters, Test, Dates, Plots, ColorTypes
22

33
ga2 = Raster(ones(91) * (-25:15)', (X(0.0:4.0:360.0), Y(-25.0:1.0:15.0), ); name=:Test)
44
ga3 = Raster(rand(10, 41, 91), (Z(100:100:1000), Y(-20.0:1.0:20.0), X(0.0:4.0:360.0)))
@@ -33,3 +33,7 @@ plot(RasterStack(ga2, ga3))
3333

3434
# DD fallback
3535
contour(ga2)
36+
37+
# Colors
38+
c = Raster(rand(RGB, Y(-20.0:1.0:20.0), X(0.0:4.0:360.0)))
39+
plot(c)

0 commit comments

Comments
 (0)