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 label to colorbar when used in abmplot #1124

Open
fieldofnodes opened this issue Jan 15, 2025 · 0 comments
Open

Add label to colorbar when used in abmplot #1124

fieldofnodes opened this issue Jan 15, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers / easy to resolve plotting

Comments

@fieldofnodes
Copy link
Contributor

When using abmplot(...) there is often a colobar with the heatmap. One can pass kwargs such as the color into this function.

Suppose I am setting up a plot and using the heatkwargs variable, perhaps I can put label here? Then if it is present the plot adds a label to the colorbar.

heatkwargs = (
    colormap=[colorant"#174036", colorant"#cc4e5c"], 
    colorrange=(0, model.harvest_time),
    label = "Plant age")

plotkwargs = (;
    agent_color=agcolor,
    agent_size=8,
    agent_marker=agshape,
    offset=aoffset,
    agentsplotkwargs=(strokewidth=1.0, strokecolor=:black),
    heatarray=arraycolor,
    heatkwargs=heatkwargs,
)

Describe the solution you'd like
A clear and concise description of what you want to happen.

Here:

function heatmap!(ax, p::_ABMPlot)
heatobs = @lift(abmplot_heatobs($(p.abmobs[].model), p.heatarray[]))
isnothing(heatobs[]) && return nothing
hmap = Makie.heatmap!(p, heatobs;
colormap=JULIADYNAMICS_CMAP, p.heatkwargs...)
p.add_colorbar[] && Colorbar(ax.parent[1, 1][1, 2], hmap, width=20)
# TODO: Set colorbar to be "glued" to axis
# Problem with the following code, which comes from the tutorial
# https://makie.juliaplots.org/stable/tutorials/aspect-tutorial/ ,
# is that it only works for axis that have 1:1 aspect ratio...
# rowsize!(fig[1, 1].layout, 1, ax.scene.px_area[].widths[2])
# colsize!(fig[1, 1].layout, 1, Aspect(1, 1.0))
return hmap
end

and here:

@recipe(_ABMPlot, abmobs) do scene
Theme(
# TODO: insert JuliaDynamics theme here?
)
Attributes(
# Axis
# ax is currently necessary to have a reference to the parent Axis. This is needed
# for optional Colorbar of heatmap and optional buttons/sliders.
# Makie's recipe system still works on the old system of Scenes which have no
# concept of a parent Axis. Makie devs plan to enable this in the future. Until then
# we will have to work around it with this "little hack".
ax=nothing,
# Agent
agent_color=JULIADYNAMICS_COLORS[1],
agent_size=15,
agent_marker=:circle,
offset=nothing,
spaceplotkwargs = NamedTuple(),
agentsplotkwargs = NamedTuple(),
# Preplot
heatarray=nothing,
heatkwargs=NamedTuple(),
add_colorbar=true,
adjust_aspect=true,
# Interactive application
add_controls=false,
# Add parameter sliders if params are provided
params=Dict(),
# Animation evolution speed
dt=nothing,
# Internal Attributes necessary for inspection, controls, etc. to work
_used_poly=false,
)
end

I just make my own plot for these situation and do not use the abmplot function.

@Datseris Datseris added enhancement New feature or request good first issue Good for newcomers / easy to resolve plotting labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers / easy to resolve plotting
Projects
None yet
Development

No branches or pull requests

2 participants