Skip to content

Request for Direct Legend Label Support for Contour Plots #30371

@tnakaicode

Description

@tnakaicode

I am writing to express my concern regarding the handling of legends for contour plots in recent versions of matplotlib. While line plots (plot) allow direct assignment of legend labels via the label argument, contour plots (contour) do not support this feature. Attempts to use the label argument with contour result in warnings, and the recommended workaround is to use dummy Line2D objects for legend handles. This approach is unintuitive and does not reflect the actual plotted lines.

Furthermore, the previously available method of assigning labels via the collections attribute (e.g., img.collections[0].set_label("label")) has been deprecated, making it difficult to associate legend entries with the actual contour lines.

I strongly request that future versions of matplotlib provide a straightforward and stable way to assign legend labels directly to contour plots, similar to how it is done for line plots. This would greatly improve usability and code clarity for users who wish to create accurate and meaningful legends for their visualizations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions