add contour

This commit is contained in:
t-bltg 2022-01-12 16:09:29 +01:00
parent cfc8e8e492
commit 1effd45e8b
2 changed files with 12 additions and 3 deletions

View File

@ -938,6 +938,7 @@ const _unicodeplots_seriestype = [
:shape, :shape,
:histogram2d, :histogram2d,
:heatmap, :heatmap,
:contour,
:spy, :spy,
] ]
const _unicodeplots_style = [:auto, :solid] const _unicodeplots_style = [:auto, :solid]

View File

@ -88,6 +88,11 @@ up_color(col::RGBA) =
(c = convert(ARGB32, col); map(Int, (red(c).i, green(c).i, blue(c).i))) (c = convert(ARGB32, col); map(Int, (red(c).i, green(c).i, blue(c).i)))
up_color(col) = :auto 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 # add a single series
function addUnicodeSeries!( function addUnicodeSeries!(
sp::Subplot{UnicodePlotsBackend}, sp::Subplot{UnicodePlotsBackend},
@ -112,16 +117,19 @@ function addUnicodeSeries!(
kw[:xlim][:] .= kw[:ylim][:] .= 0 kw[:xlim][:] .= kw[:ylim][:] .= 0
return UnicodePlots.densityplot(x, y; kw...) return UnicodePlots.densityplot(x, y; kw...)
elseif st == :heatmap 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( return UnicodePlots.heatmap(
series[:z].surf; series[:z].surf;
zlabel = sp[:colorbar_title], zlabel = sp[:colorbar_title],
colormap = cmap, colormap = up_cmap(series),
kw..., kw...,
) )
elseif st == :spy elseif st == :spy
return UnicodePlots.spy(series[:z].surf; kw...) 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 end
# now use the ! functions to add to the plot # now use the ! functions to add to the plot