Not all subplots are updated after the widget event

Hello!

I wrote simple code, but it seems it doesn’t work properly. When I click on the button, only the first one subplot is updated.

If I try to change any other atributes of subplots (such as x or y axis values) it works correct.

Am I doing something wrong, or is there any workaround you can suggest to help me, fix this? Any help is highly appreciated.

Update: Also when I try to download plot using “download plot as a png” error is occuring (shown on the last image)

import ipywidgets as widgets
from plotly.subplots import make_subplots

subplot = make_subplots(rows=1, cols=3)
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=1, name='1', orientation='v')
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=2, name='2', orientation='v')
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=3, name='3', orientation='v')


def change_orientation(obj):
    if obj.new == True:
        for item in fig_widg.data:
            item.orientation = 'h'
    else:
        for item in fig_widg.data:
            item.orientation = 'v'

is_horizontal = widgets.Checkbox(description='Horizontal')
is_horizontal.observe(change_orientation, 'value')
            
    
fig_widg = go.FigureWidget(subplot)
box = widgets.VBox([is_horizontal, fig_widg])
box



fig3

Hi @Severitatem,

After unsuccessfully trying to make it work, it looks like a bug with FigureWidget to me. You should open a Github issue to this end.

In the mean time you can do this:

import ipywidgets as widgets
from plotly.subplots import make_subplots

subplot = make_subplots(rows=1, cols=3)
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=1, name='1', orientation='v')
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=2, name='2', orientation='v')
subplot.add_bar(x=[1,2,3], y=['a', 'b', 'c'], row=1, col=3, name='3', orientation='v')


def change_orientation(obj):
    subplot.update_traces(orientation='h' if obj.new else 'v')
    fig_widg.data=[]
    fig_widg.add_traces(subplot.data)
    fig_widg.layout=subplot.layout

is_horizontal = widgets.Checkbox(description='Horizontal')
is_horizontal.observe(change_orientation, 'value')
               
fig_widg = go.FigureWidget()
box = widgets.VBox([is_horizontal, fig_widg])
box
1 Like

Thanks a lot for help! Your code work as I needed.