Highlight Violin Trace in a certain Range

Hello there,

I am using violin traces to represent density distributions, and Iโ€™d like to highlight values above a certain one without adding shapes to the plot, because i feel like they introduce visual noise when there are many traces, or using hover strategies (the resulting image will be printed).

My first idea was to try to change the color of the trace from that value upwards, but Iโ€™ve found no way to do that. Now I am trying to draw an additional violin trace that hides the previous one, but I am having difficulties replicating the original shape by changing the width and the bandwidth.

Anyone knows an easier method? Hereโ€™s a snippet of my code and the resulting plot:

   boolean1, boolean2, boolean3 = False, False, False
   fig = go.Figure()
   for pla in planes:
       bndwsilverman = 1.059 * np.min([np.std(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)]),
                                       (np.percentile(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)], 75) -
                                        np.percentile(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)], 25))
                                       / 1.349]) * \
                       np.power(len(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)]), -(1 / 5))
       bndwlimit = (np.max(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)]) -
                    np.min(data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)])) / 100
       bndwsample = np.max([bndwsilverman, bndwlimit])
       print(bndwsilverman, bndwlimit)

       if boolean1 is False:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   y=data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   side='negative', width=1,
                                   name='-0.01', legendgroup='-0.01', line=dict(color='green')))
           boolean1 = True
       else:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   y=data['w'][(data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   side='negative', width=1,
                                   legendgroup='-0.01', line=dict(color='green'), showlegend=False))
       if boolean2 is False and \
               len(data['w'][(data['WW'] == "> 5") & (data['rel'] == '-0.01') & (data['pos'] == pla)]) > 0:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '-0.01') & (data['WW'] == '> 5') & (data['pos'] == pla)],
                                   y=data['w'][(data['WW'] == "> 5") & (data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   side='negative', width=0.05, bandwidth=bndwsample,
                                   name='-0.01 over next WW', legendgroup='-0.01 over next WW',
                                   line=dict(color='red')))
           boolean2 = True
       elif boolean2 is True and \
               len(data['w'][(data['WW'] == "> 5") & (data['rel'] == '-0.01') & (data['pos'] == pla)]) > 0:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '-0.01') & (data['WW'] == '> 5') & (data['pos'] == pla)],
                                   y=data['w'][(data['WW'] == "> 5") & (data['rel'] == '-0.01') & (data['pos'] == pla)],
                                   side='negative', width=1, bandwidth=bndwsample,
                                   legendgroup='-0.01 over next WW', line=dict(color='red'), showlegend=False))
       if boolean3 is False:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '+0.01') & (data['pos'] == pla)],
                                   y=data['w'][(data['rel'] == '+0.01') & (data['pos'] == pla)],
                                   side='positive', width=1,
                                   name='+0.01', legendgroup='+0.01', line=dict(color='blue')))
           boolean3 = True
       else:
           fig.add_trace(go.Violin(x=data['pos'][(data['rel'] == '+0.01') & (data['pos'] == pla)],
                                   y=data['w'][(data['rel'] == '+0.01') & (data['pos'] == pla)],
                                   side='positive', width=1,
                                   legendgroup='+0.01', line=dict(color='blue'), showlegend=False))
   fig.update_traces(line=dict(width=1), points=False)
   fig.update_layout(violingap=0, violinmode='overlay', width=1000)
   fig.update_yaxes(range=[1., 5.])
   fig.show()

Ideally, the red violin trace would perfectly โ€œhideโ€ or โ€œcoverโ€ the green one from a certain value upwards.