From 1effd45e8b21e81bdfc02302bede72ee6e708ab9 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Wed, 12 Jan 2022 16:09:29 +0100 Subject: [PATCH] add contour --- src/backends.jl | 1 + src/backends/unicodeplots.jl | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backends.jl b/src/backends.jl index 62d9d97b..a4857adc 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -938,6 +938,7 @@ const _unicodeplots_seriestype = [ :shape, :histogram2d, :heatmap, + :contour, :spy, ] const _unicodeplots_style = [:auto, :solid] diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 187520ba..c88f5e28 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -88,6 +88,11 @@ up_color(col::RGBA) = (c = convert(ARGB32, col); map(Int, (red(c).i, green(c).i, blue(c).i))) up_color(col) = :auto +function up_cmap(series) + rng = range(0, 1, length = length(UnicodePlots.COLOR_MAP_DATA[:viridis])) + [(red(c), green(c), blue(c)) for c in get(get_colorgradient(series), rng)] +end + # add a single series function addUnicodeSeries!( sp::Subplot{UnicodePlotsBackend}, @@ -112,16 +117,19 @@ function addUnicodeSeries!( kw[:xlim][:] .= kw[:ylim][:] .= 0 return UnicodePlots.densityplot(x, y; kw...) elseif st == :heatmap - rng = range(0, 1, length = length(UnicodePlots.COLOR_MAP_DATA[:viridis])) - cmap = [(red(c), green(c), blue(c)) for c in get(get_colorgradient(series), rng)] return UnicodePlots.heatmap( series[:z].surf; zlabel = sp[:colorbar_title], - colormap = cmap, + colormap = up_cmap(series), kw..., ) elseif st == :spy return UnicodePlots.spy(series[:z].surf; kw...) + elseif st == :contour + return UnicodePlots.contourplot( + x, y, series[:z].surf; + levels=series[:levels], colormap = up_cmap(series), kw... + ) end # now use the ! functions to add to the plot