Sort y axis for traces (part of a figure)

Hi, my figure is composed of multiple traces depending on what attributes the user would like to see. So, a figure can consist of multiple traces, for example:

if id:
    id_traces = px.scatter().data
    for trace in id_traces:
        fig.add_trace(trace)

if year:
    year_traces = px.scatter().data
    for trace in year_traces :
        fig.add_trace(trace)

Now, if I want to sort the y-axis showing the year only, is it possible? I donโ€™t want to sort the whole y-axis, because that would just sort the whole figure and interfere with other traces (like the IDs). I tried to update the year plot before adding it to fig:

if year:
    year_plot = px.scatter()
    year_plot .update_yaxes(categoryorder='category ascending')
    year_traces = year_plot .data
    for trace in year_traces :
        fig.add_trace(trace)

But that unfortunately did not work, unless I did something wrong (in that case, please let me know)!