I haven’t understood yet, because it’s not clear how is defined your fig.data, i.e. how many traces is contains.
Eventually take a look at this answer: Advanced Dropdown Menus with Plotly if you want to selectively reset or ignore certain properties when restyling. Besides 'undefined'
there is the option 'null'
. `null resets a property to the default one, while
undefined`` applies no change to the current state.
*In the above answer replace “two each” by “To each”