Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: Legend does not avoid line collections #23353

Open
@Qrox

Description

@Qrox

Bug summary

When adding legend to an axes withloc set to"best", the created legend does not try to avoid line collections added viaadd_collection.

It seems_auto_legend_data only returns the offsets of a collection, so only scatter-plot-like collections are avoided by the legend. Line collections that are intended to draw data lines always have zero orNone offset values and are thus not avoided when creating the legend.

Code for reproduction

importmatplotlib.pyplotaspltimportmatplotlib.collectionsfig,ax=plt.subplots(1,1,figsize=(7,4),constrained_layout=True)lc=matplotlib.collections.LineCollection([[(0,0), (1,1)]],label='Foo')ax.add_collection(lc)ax.legend()plt.show()

Actual outcome

image

Expected outcome

image

Additional information

I work this around by using a patch that essentially adds the following code after the branch here:

elifisinstance(artist,Patch):

        elif (            isinstance(artist, Collection)            and (                artist.get_offsets() is None                or (np.array(artist.get_offsets()) == 0).all()            )        ):            transform, _, _, paths = artist._prepare_points()            lines += [transform.transform_path(path) for path in paths]

But I'm not familar enough with the code to say this won't create other problems, and it seems to be extremely slow with large line collections.

Operating system

No response

Matplotlib Version

3.5.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp