Skip to content

Commit

Permalink
add contour
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Jan 12, 2022
1 parent cfc8e8e commit 1effd45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ const _unicodeplots_seriestype = [
:shape,
:histogram2d,
:heatmap,
:contour,
:spy,
]
const _unicodeplots_style = [:auto, :solid]
Expand Down
14 changes: 11 additions & 3 deletions src/backends/unicodeplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down

0 comments on commit 1effd45

Please sign in to comment.