From 3152d4b4fead2f15b0745f39a3d0877e1c0a679e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 11 Apr 2020 11:17:23 +0200 Subject: [PATCH] fix tests for gr --- Project.toml | 2 ++ src/Plots.jl | 1 + src/backends/gr.jl | 24 +++++++++++++++++------- src/examples.jl | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 84266b53..00ffc174 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "1.0.14" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" @@ -32,6 +33,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] +ColorSchemes = "3.6" Contour = "0.5" FFMPEG = "0.2, 0.3" FixedPointNumbers = "0.6, 0.7, 0.8" diff --git a/src/Plots.jl b/src/Plots.jl index b849e609..0482e0ad 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -19,6 +19,7 @@ import RecipesBase: plot, plot!, animate, is_explicit using Base.Meta @reexport using PlotUtils @reexport using PlotThemes +@reexport using ColorSchemes import Showoff import StatsBase import JSON diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d7e93a0c..b799934e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -880,7 +880,8 @@ function _update_min_padding!(sp::Subplot{GRBackend}) tickfont(zaxis), halign = (zaxis[:mirror] ? :left : :right), valign = (:top, :vcenter, :bottom)[sign(zaxis[:rotation]) + 2], - rotation = zaxis[:rotation] + rotation = zaxis[:rotation], + color = zaxis[:tickfontcolor], ) l = 0.01 + first(gr_get_ticks_size(zticks, zaxis[:rotation])) w = 1mm + gr_plot_size[1] * l * px @@ -1238,7 +1239,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) tickfont(xaxis), halign = (:left, :hcenter, :right)[sign(xaxis[:rotation]) + 2], valign = (xaxis[:mirror] ? :bottom : :top), - rotation = xaxis[:rotation] + rotation = xaxis[:rotation], + color = xaxis[:tickfontcolor], ) yt = if sp[:framestyle] == :origin 0 @@ -1268,7 +1270,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) tickfont(yaxis), halign = (:left, :hcenter, :right)[sign(yaxis[:rotation]) + 2], valign = (yaxis[:mirror] ? :bottom : :top), - rotation = yaxis[:rotation] + rotation = yaxis[:rotation], + color = yaxis[:tickfontcolor], ) xt = if sp[:framestyle] == :origin 0 @@ -1298,7 +1301,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) tickfont(zaxis), halign = (zaxis[:mirror] ? :left : :right), valign = (:top, :vcenter, :bottom)[sign(zaxis[:rotation]) + 2], - rotation = zaxis[:rotation] + rotation = zaxis[:rotation], + color = zaxis[:tickfontcolor], ) xt = if sp[:framestyle] == :origin 0 @@ -1662,8 +1666,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif st == :heatmap zmin, zmax = clims fillgrad = _as_gradient(series[:fillcolor]) - colors = plot_color.(nan_get(fillgrad, z, clims), series[:fillalpha]) - rgba = gr_color.(colors) if !ispolar(sp) GR.setspace(clims..., 0, 90) x, y = heatmap_edges(series[:x], sp[:xaxis][:scale], series[:y], sp[:yaxis][:scale], size(series[:z])) @@ -1674,11 +1676,16 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # pdf output, and also supports alpha values. # Note that drawimage draws uniformly spaced data correctly # even on log scales, where it is visually non-uniform. + colors = plot_color.(nan_get(fillgrad, z, clims), series[:fillalpha]) + rgba = gr_color.(colors) GR.drawimage(first(x), last(x), last(y), first(y), w, h, rgba) else if something(series[:fillalpha],1) < 1 || any(_gr_gradient_alpha .< 1) @warn "GR: transparency not supported in non-uniform heatmaps. Alpha values ignored." end + colors = nan_get(fillgrad, z, clims) + z_normalized = map(c -> c == invisible() ? 256/255 : getinverse(fillgrad, c), colors) + rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized] GR.nonuniformcellarray(x, y, w, h, rgba) end else @@ -1693,8 +1700,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if series[:y][end] != ny @warn "Right now only the maximum value of y (r) is taken into account." end + colors = nan_get(fillgrad, z, clims) + z_normalized = map(c -> c == invisible() ? 256/255 : getinverse(fillgrad.colors, c), colors) + rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized] # GR.polarcellarray(0, 0, phimin, phimax, ymin, ymax, nx, ny, colors) - GR.polarcellarray(0, 0, phimin, phimax, 0, ymax, nx, ny, colors) + GR.polarcellarray(0, 0, phimin, phimax, 0, ymax, nx, ny, rgba) # Right now only the maximum value of y (r) is taken into account. # This is certainly not perfect but nonuniform polar array is not yet supported in GR.jl end diff --git a/src/examples.jl b/src/examples.jl index 8358ac02..3d0ec356 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -74,7 +74,7 @@ const _examples = PlotExample[ rand(11, 4), lab = "lines", w = 3, - palette = :grays, + palette = cgrad(:grays), fill = 0, α = 0.6, ) @@ -322,7 +322,7 @@ const _examples = PlotExample[ plot( Plots.fakedata(100, 10), layout = 4, - palette = [:grays :blues :heat :lightrainbow], + palette = cgrad.([:grays :blues :heat :lightrainbow]), bg_inside = [:orange :pink :darkblue :black], ) end