Skip to content

Commit

Permalink
PyPlot: fix label position and annotate color bar
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaap committed Nov 18, 2024
1 parent efc3535 commit 55d0180
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 55d0180

Please sign in to comment.