Problem with stacking of markers in a legend

I am plotting football ball markers as two separate scatter plots, one with a hexagon path and one with pentagon path. However, I can only get them to stack in the legend using a HandlerTuple in the legend. This requires knowledge of how legend handles and labels work and also needs to be done at the end of a plot.

If possible, I would like to hide the creation of the legend marker in a class method using a custom Handler and update the default handler map of the first scatter plot. However I have not been able to align the custom handler with the default legend markers created by scatter.

Here’s my problem:

I am not sure what to do next. Any help appreciated! Here’s the code for the various options I have tried so far:

I managed to fix it. _default_update_prop was overwriting the multiple colors.

class HandlerFootball(HandlerPathCollection):

def create_collection(self, orig_handle, sizes, offsets, transOffset):
    edgecolor = orig_handle.get_edgecolor()[0]
    facecolor = orig_handle.get_facecolor()[0]
    sizes = [size*0.249 for size in sizes]
    p = type(orig_handle)([football_hexagon_marker, football_pentagon_marker],
                          facecolors=[facecolor, edgecolor],
    return p

def _default_update_prop(self, legend_handle, orig_handle):
    facecolor = legend_handle.get_facecolor()
    edgecolor = legend_handle.get_edgecolor()
1 Like