Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyPlot: fix label position and annotate color bar #39

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading