Skip to content

Commit

Permalink
Merge pull request #39 from WIAS-PDELib/feature/pyplot-correct-colobar
Browse files Browse the repository at this point in the history
PyPlot: fix label position and annotate color bar
  • Loading branch information
jpthiele authored Nov 27, 2024
2 parents 0d84e0f + 702fbae commit 86a488e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [unreleased]

### Added

- `gridplot` with `PyPlot` has now a color bar with annotation `boundary regions`

## [1.9.0] - 2024-11-25

### Added
Expand Down
33 changes: 24 additions & 9 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,45 @@ 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(max(ncellregions, 5))
cdata = ax.tripcolor(
# PyPlot.ColorMap cannot handle n ≤ 1, TODO: use single color instead of a color map
cmap = region_cmap(max(2, ncellregions))
bcmap = bregion_cmap(max(2, nbfaceregions))

cell_colors = cellcolors(grid, ctx[:cellcoloring])

# dummy plot to get a correct color bar for the boundary data
bcdata = ax.tripcolor(
tridat[1][1:3], tridat[2][1:3]; # extract a single point from the original triangulation
facecolors = cell_colors[1:1], # only one triangle!
cmap = PyPlot.ColorMap(bcmap, length(bcmap)),
vmin = 0.5,
vmax = length(bcmap) + 0.5,
)

ax.tripcolor(
tridat...;
facecolors = cellcolors(grid, ctx[:cellcoloring]),
facecolors = cell_colors,
cmap = PyPlot.ColorMap(cmap, length(cmap)),
vmin = 1.0,
vmax = length(cmap),
)

if ctx[:show_colorbar]
if ctx[:colorbar] == :horizontal
cbar = fig.colorbar(
cdata;
bcdata;
ax = ax,
ticks = collect(1:length(cmap)),
ticks = collect(1:length(bcmap)),
orientation = "horizontal",
label = "boundary regions",
)
end

if ctx[:colorbar] == :vertical
cbar = fig.colorbar(
cdata;
bcdata;
ax = ax,
ticks = collect(1:length(cmap)),
ticks = collect(1:length(bcmap)),
orientation = "vertical",
label = "boundary regions",
)
end
end
Expand Down

0 comments on commit 86a488e

Please sign in to comment.