0

I have a main Figure and a list of other figures in a list called main_plot. Each plot is connected to the first one to have the same x-asis zoom with x_range=main_plot.x_range

What i would like to achieve is to have a checkbox, and if it is checked I would like to show additional plots.

So far I have a working code based on an example: Bokeh: Widget to Show/Hide Figures

Here the response uses a column() function, I was able to implement it:

toogle_subplots = generate_additional_subplots(main_plot)
final_grid += toogle_subplots
col = column()
checkbox = CheckboxGroup(labels=["Plot"],
                         active=[0], width=100)

callback = CustomJS(args=dict(plots=toogle_subplots, col=col, checkbox=checkbox), code="""
const children = []
for (const i of checkbox.active) {
    for (const j of plots) {
      children.push(j)
    }

}
col.children = children
""")
checkbox.js_on_change('active', callback)
final_grid += [checkbox, col]

grid = layout(final_grid, sizing_mode='stretch_width')

However, in my case, I work with grid, and not columns, and for some reason the plots inside the column are wider that the normal. In the example above I want to add toogle_subplots which is a list of Figures to the grid if the checkbox is checked. It works, but as I add toogle_subplots to the Layout without the JS callback, their width is different.

Picture: enter image description here

The two rows above the checkbox and the two below are the Figures inside toogle_subplots, and they have a different width. Their behavior is good, they follow the zoom and pan of the main plot.

Is there an easier solution to this problem?

Gábor Erdős
  • 3,599
  • 4
  • 24
  • 56
  • most models now have a "visible" attribute so you can hide a full figure just by doing "fig.visible = False". I think it would be better to show/hide your plots rather than adding/removing children to a column layout. – Seb Dec 19 '19 at 22:07
  • @Seb Thanks a lot, I will try. I also found out that the described behavior is caused by a bug, and found a solution to it. I will answer this question with my solution. – Gábor Erdős Dec 20 '19 at 14:50

0 Answers0