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

[BUG] plot_title affects subplot indexing because implemented as additional subplot which just emulating plot title #4612

Open
EldarAgalarov opened this issue Jan 1, 2023 · 0 comments
Labels

Comments

@EldarAgalarov
Copy link

EldarAgalarov commented Jan 1, 2023

This code creates plot with 2 subplots with indexes 1 and 2 and length = 2:

using Plots

Plots.reset_defaults()
default(
    background_color = :darkgray,
    background_color_inside = :lightgray
)

p1 = plot(1:100, rand(100))
p2 = plot(1:100, rand(100))
p = plot(p1, p2, layout = grid(2, 1))

p_len = length(p) # 2 subplots
sp1 = p[1] # subplot 1
sp2 = p[2] # subplot 2

When adding plot_title attribute to parent plot then indexing becoming broken because plot_title is just additional subplot that added at the top of the layout:

using Plots

Plots.reset_defaults()
default(
    background_color = :darkgray,
    background_color_inside = :lightgray
)

p1 = plot(1:100, rand(100))
p2 = plot(1:100, rand(100))
p = plot(p1, p2, layout = grid(2, 1), plot_title = "plot_title")

p_len = length(p) # 3 subplots (added additional subplot that contains title)
pt = p[1] # plot title
sp1 = p[2] # subplot 1 (index changed!)
sp2 = p[3] # subplot 2 (index changed!)

This is definitely a bug, because it breaks existing code that relies on accessing subplots based on indices.
Adding plot_title is just cosmetic change, not structural and shouldn't affect on subplot indexing.

Related bug that affects background coloring of plot_title area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant