diff --git a/src/pyplot.jl b/src/pyplot.jl index 4fc41f3..f5e6ab0 100644 --- a/src/pyplot.jl +++ b/src/pyplot.jl @@ -225,24 +225,39 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid) brflag = ones(Bool, nbfaceregions) ax.set_aspect(ctx[:aspect]) tridat = tridata(grid, ctx[:gridscale]) - cmap = region_cmap(ncellregions) + # PyPlot.ColorMap cannot handle n ≤ 1, TODO: use other color mappings! + cmap = region_cmap( max( 2, ncellregions ) ) + bcmap = bregion_cmap( max( 2, nbfaceregions ) ) + + bcdata = ax.tripcolor(tridat...; + facecolors = cellcolors(grid, ctx[:cellcoloring]), + cmap = PyPlot.ColorMap(bcmap, length(bcmap)), + vmin = 0.5, + vmax = length(bcmap)+0.5,) + + # this simply overwrites the plotting done in "bcdata = " ... cdata = ax.tripcolor(tridat...; - facecolors = cellcolors(grid, ctx[:cellcoloring]), - cmap = PyPlot.ColorMap(cmap, length(cmap)), - vmin = 1.0, - vmax = length(cmap),) + facecolors = cellcolors(grid, ctx[:cellcoloring]), + cmap = PyPlot.ColorMap(cmap, length(cmap)), + vmin = 0.5, + vmax = length(cmap)+0.5,) + if ctx[:colorbar] == :horizontal - cbar = fig.colorbar(cdata; + cbar = fig.colorbar(bcdata; ax = ax, - ticks = collect(1:length(cmap)), - orientation = "horizontal",) + ticks = collect(1:length(bcmap)), + orientation = "horizontal", + label = "boundary regions", + ) end if ctx[:colorbar] == :vertical - cbar = fig.colorbar(cdata; + cbar = fig.colorbar(bcdata; ax = ax, - ticks = collect(1:length(cmap)), - orientation = "vertical",) + ticks = collect(1:length(bcmap)), + orientation = "vertical", + label = "boundary regions", + ) end ax.triplot(tridat...; color = "k", linewidth = ctx[:linewidth])