Skip to content

Duplicate legend entries when plotting on sliced spanned axes with legend=True #597

@ToryDeng

Description

@ToryDeng

When creating a figure with a spanned subplot layout using a 2D array, slicing the axes grid to access the spanned subplot (e.g., axs[0, :2]) and calling .scatter() with legend=True results in duplicate legend entries.

Reproducible Example:

import numpy as np
import ultraplot as uplt

array = np.array(
    [[0.71510417, 0.18342202],
    [0.63857324, 0.49007551],
    [0.34293048, 0.81424364],
    [0.93123847, 0.54010325],
    [0.12053916, 0.67823549]]
)

fig, axs = uplt.subplots(np.array([[1, 1, 2], [3, 4, 5]]))
ax = axs[0, :2] 

ax.scatter(
    x=array[:, 0], y=array[:, 1], c="grey", label="data", legend=True
)
Image

A quick workaround is to replace ax = axs[0, :2] with ax = axs[0]. However, I'm not sure if this duplicate behavior is intended, or if the usage of axs[0, :2] is simply discouraged in ultraplot.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions