How do I use one legend filter to filter two graphs?

Hey @M1sha welcome to the forums.

Here an MRE:

import dash
from dash import html, dcc, Input, Output, Patch
import plotly.graph_objects as go
import numpy as np

figure = go.Figure()

for i in range(4):
    figure.add_trace(
        go.Scatter(
            x=np.arange(1, 10),
            y=np.arange(1, 10) + 2 * i,
        )
    )

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        dcc.Graph(
            id='graph_1',
            figure=figure

        ),
        dcc.Graph(
            id='graph_2',
            figure=figure
        ),
    ]
)


@app.callback(
    Output('graph_2', 'figure'),
    Input('graph_1', 'restyleData'),
    prevent_initial_call=True
)
def update(data):
    info, trace_list = data
    states = info['visible']

    patched = Patch()
    for state, trace in zip(states, trace_list):
        patched['data'][trace].update({'visible': state})
    return patched


if __name__ == "__main__":
    app.run(debug=True)

traces
mred patch