Skip to content

Error during legend creation with mixture of marks #3023

@mwaskom

Description

@mwaskom

Here's a minimal example, it seems that you need all three layers to trigger the error:

(
    so.Plot(penguins, "bill_length_mm", "bill_depth_mm", color="species")
    .add(so.Dots())
    .add(so.Line(), so.PolyFit(1))
    .add(so.Line(), so.PolyFit(2))
)
Traceback
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File ~/miniconda3/envs/seaborn-py39-latest/lib/python3.9/site-packages/IPython/core/formatters.py:343, in BaseFormatter.__call__(self, obj)
    341     method = get_real_method(obj, self.print_method)
    342     if method is not None:
--> 343         return method()
    344     return None
    345 else:

File ~/code/seaborn/seaborn/_core/plot.py:275, in Plot._repr_png_(self)
    273 def _repr_png_(self) -> tuple[bytes, dict[str, float]]:
--> 275     return self.plot()._repr_png_()

File ~/code/seaborn/seaborn/_core/plot.py:814, in Plot.plot(self, pyplot)
    810 """
    811 Compile the plot spec and return the Plotter object.
    812 """
    813 with theme_context(self._theme_with_defaults()):
--> 814     return self._plot(pyplot)

File ~/code/seaborn/seaborn/_core/plot.py:847, in Plot._plot(self, pyplot)
    844     plotter._plot_layer(self, layer)
    846 # Add various figure decorations
--> 847 plotter._make_legend(self)
    848 plotter._finalize_figure(self)
    850 return plotter

File ~/code/seaborn/seaborn/_core/plot.py:1608, in Plotter._make_legend(self, p)
   1605 for i, artist in enumerate(existing_artists):
   1606     # Matplotlib accepts a tuple of artists and will overlay them
   1607     if isinstance(artist, tuple):
-> 1608         artist += artist[i],
   1609     else:
   1610         existing_artists[i] = artist, artists[i]

IndexError: tuple index out of range
<seaborn._core.plot.Plot at 0x144c1f6a0>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions