Pattern shape changing data

Hey there,

I’m using dash for a sports application. I would like to have ‘home’ and ‘away’ games to have a different pattern.
Now each row has an opponent, date and home or away. Then row name is the color as it specifies the type of data (I have an histogram with two types of data). My x axis set to date, as I want to order by date. So far so good, However if I add the pattern_shape and set it to location my graph changes? Also, it adds the patterns to the wrong games.

c = 'Row Name'
    match_files = match_files.sort_values('DATE')
    match_files['Sorter'] = match_files['DATE'] + match_files['OPPONENT']
    histo = px.histogram(match_files, x="DATE", color=c, color_discrete_sequence=['purple', 'orange'], title='Communicatie per wedstrijd') 
    histo.add_hline(eredivisie_average, line_color='red', line_dash='dash')
    histo.add_hline(ucl_average, line_color='purple', line_dash='dash')

    x_axis = match_files['DATE'].unique()
    eredivisie_x = convert_h_line_to_trace(eredivisie_average, len(x_axis))
    ucl_x = convert_h_line_to_trace(ucl_average, len(x_axis))



    histo.add_trace(go.Scatter(x=x_axis, y=eredivisie_x, mode='lines', name='Eredivisie gemiddelde', line={
            'color': 'red',
            'width': 1,
            'dash': 'dash'}))

    histo.add_trace(go.Scatter(x=x_axis, y=ucl_x, mode='lines', name='UCL gemiddelde', line={
        'color': 'purple',
        'width': 1,
        'dash': 'dash'}))

    clubs = match_files['Sorter'].unique()

    for c, club in enumerate(clubs):
        score = 0
        club = ''.join([i for i in club if not i.isdigit()])
        for i, src in zip(range(len(image_names)), image_names):
            club_image_name = src.split('.')[0]
            temp_score = SequenceMatcher(a=club_image_name, b=club).ratio()
            if temp_score > score:
                score = temp_score
                img_scr = src
        logo = base64.b64encode(open('./logos/' + img_scr, 'rb').read())
        histo.add_layout_image(
            source='data:image/png;base64,{}'.format(logo.decode()),
            xref="x",
            yref="y domain",
            x=c,
            y=0,
            xanchor="center",
            yanchor="bottom",
            sizex=1,
            sizey=1,
        )


    histo.update_layout(
        xaxis_title="Tegenstander",
        yaxis_title="Communicatie",
        legend_title="Communicatie type",
        template='plotly_dark',
        font=dict(size=7),
    )
    histo.update_layout(legend=dict(
        orientation="h",
        yanchor="bottom",
        y=1.02,
        xanchor="right",
        x=1
    ))
    return histo


Seems as if its using a different ordering for the ‘pattern_shape’ and starts ordering that alphabetically

1 Like

HI @TomBoomstra
Welcome to the Plotly Dash community.

That’s a good question. I’ve never tried adding pattern_shape to plots. Can you share your code with us? Try to make it a minimal working example (MWE) so we can replicate your graphs on our computer please.

Hey Adam, been some busy days, I’ll try to get a proper MWE by tomorrow.