Skip to content

FIX: Deprecate using clabel() with filled contours#31347

Draft
timhoffm wants to merge 1 commit intomatplotlib:mainfrom
timhoffm:deprecate-contourf-clabel
Draft

FIX: Deprecate using clabel() with filled contours#31347
timhoffm wants to merge 1 commit intomatplotlib:mainfrom
timhoffm:deprecate-contourf-clabel

Conversation

@timhoffm
Copy link
Member

It's never been intended to be used that way and may cause inconsistent plots. Closes #31344.

@timhoffm timhoffm force-pushed the deprecate-contourf-clabel branch from 3b2af05 to a5b4b7f Compare March 22, 2026 10:40
Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing test was added at #16329. I assume the contourf part was just done for completeness since the issue only seems concerned with labels on a contour plot.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using `~.Axes.clabel` to label filled contours created with `~.Axes.contourf` is deprecated. ``clabel()``
is designed to label contour lines (`.Axes.coutour`), and using it with filled contours can lead to inconsistent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is designed to label contour lines (`.Axes.coutour`), and using it with filled contours can lead to inconsistent
is designed to label contour lines (`.Axes.contour`), and using it with filled contours can lead to inconsistent

is designed to label contour lines (`.Axes.coutour`), and using it with filled contours can lead to inconsistent
plots. If you want to add labels to filled contours, the recommended approach is to first create the filled contours
with `~.Axes.contourf`, then overlay contour lines using `~.Axes.contour`, and finally apply `~.Axes.clabel` to those
contour lines for labeling.
Copy link
Member

@rcomer rcomer Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a link to the contour demo that shows this being done?

It's never been intended to be used that way and may cause inconsistent
plots. Closes matplotlib#31344.
@timhoffm timhoffm force-pushed the deprecate-contourf-clabel branch from a5b4b7f to 46baee2 Compare March 22, 2026 11:45
@timhoffm timhoffm marked this pull request as draft March 22, 2026 12:39
@timhoffm
Copy link
Member Author

Still need to fix test failures.

@rcomer
Copy link
Member

rcomer commented Mar 22, 2026

Should there also be a deprecated directive on the clabel docstring? Maybe not if this was never supposed to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Adding contour labels affects the shape of filled contours

2 participants