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

Add show_colorbar kwarg #42

Merged
merged 1 commit into from
Nov 24, 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

- new key word argument `show_colorbar` (default=true) to toggle the color bar next to grid plots

## [1.8.2] - 2024-11-08

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ function default_plot_kwargs()
:dim => Pair(1, "Data dimension for PlutoVista plot"),
:regions => Pair(:all, "List of regions to plot"),
:species => Pair(1, "Number of species to plot or number of species in regions"),
:spacing => Pair(nothing, "Removed from API"))
:spacing => Pair(nothing, "Removed from API"),
:show_colorbar => Pair(true, "Show color bar next to grid plots"))
end

#
Expand Down
46 changes: 24 additions & 22 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,28 +496,30 @@ function makescene_grid(ctx)
ncol = length(ctx[:cmap])
nbcol = length(ctx[:bcmap])
# fontsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize]
if ctx[:colorbar] == :vertical
GL[1, 2] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:cmap]; categorical = true),
limits = (0.5, ncol+0.5),
ticks = 1:ncol,
width = 15,)
GL[1, 3] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:bcmap]; categorical = true),
limits = (0.5, nbcol+0.5),
ticks = 1:nbcol,
width = 15,)
elseif ctx[:colorbar] == :horizontal
GL[2, 1] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:cmap]; categorical = true),
limits = (1, ncol),
height = 15,
vertical = false,)
GL[3, 1] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:bcmap]; categorical = true),
limits = (1, nbcol),
height = 15,
vertical = false,)
if ctx[:show_colorbar]
if ctx[:colorbar] == :vertical
GL[1, 2] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:cmap]; categorical = true),
limits = (0.5, ncol+0.5),
ticks = 1:ncol,
width = 15,)
GL[1, 3] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:bcmap]; categorical = true),
limits = (0.5, nbcol+0.5),
ticks = 1:nbcol,
width = 15,)
elseif ctx[:colorbar] == :horizontal
GL[2, 1] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:cmap]; categorical = true),
limits = (1, ncol),
height = 15,
vertical = false,)
GL[3, 1] = XMakie.Colorbar(ctx[:figure];
colormap = XMakie.cgrad(ctx[:bcmap]; categorical = true),
limits = (1, nbcol),
height = 15,
vertical = false,)
end
end
GL
end
Expand Down
2 changes: 2 additions & 0 deletions src/plutovista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ function gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{2}}, grid)
edges = edges,
edgemarkers = edgemarkers,
edgecolormap = bcmap,
show_colorbar = ctx[:show_colorbar],
aspect = ctx[:aspect],
xlabel = ctx[:xlabel],
ylabel = ctx[:ylabel],
Expand Down Expand Up @@ -358,6 +359,7 @@ function gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{3}}, grid)
facemarkers = facemarkers,
gridscale = ctx[:gridscale],
facecolormap = bcmap,
show_colorbar = ctx[:show_colorbar],
outlinealpha = ctx[:outlinealpha],
xlabel = ctx[:xlabel],
ylabel = ctx[:ylabel],
Expand Down
24 changes: 13 additions & 11 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,20 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid)
cmap = PyPlot.ColorMap(cmap, length(cmap)),
vmin = 1.0,
vmax = length(cmap),)
if ctx[:colorbar] == :horizontal
cbar = fig.colorbar(cdata;
ax = ax,
ticks = collect(1:length(cmap)),
orientation = "horizontal",)
end
if ctx[:show_colorbar]
if ctx[:colorbar] == :horizontal
cbar = fig.colorbar(cdata;
ax = ax,
ticks = collect(1:length(cmap)),
orientation = "horizontal",)
end

if ctx[:colorbar] == :vertical
cbar = fig.colorbar(cdata;
ax = ax,
ticks = collect(1:length(cmap)),
orientation = "vertical",)
if ctx[:colorbar] == :vertical
cbar = fig.colorbar(cdata;
ax = ax,
ticks = collect(1:length(cmap)),
orientation = "vertical",)
end
end

ax.triplot(tridat...; color = "k", linewidth = ctx[:linewidth])
Expand Down
Loading