Labelling contours manually via clabel adds spurious new lines to the plot

27 Views Asked by At

I have a set of contours made with plt.contourf. I am now trying to label the contours with plt.clabel with manual=True. This opens the plot, and prompts me to click on the figure to add labels. When I do this, new spurious contours are added to the plot, which are not correct given the data. Some labels are drawn correctly, but most are not.

I came across this old question which seems to be describing the same issue, though an answer there claims that this was identified as a bug and fixed years ago. Has anyone run into this?

Before clicking:

enter image description here

After a few clicks:

enter image description here

1

There are 1 best solutions below

0
On

Apologies that my question does not have a minimal working example; when trying to write, one, I found that I could no reproduce the problem on one machine, but I could on another, with identical code. After some sleuthing, my conclusion was:

This bug was not present in version 3.6 of matplotlib. Sometime after this, it must have been re-introduced. It was not fixed again until matplotlib version 3.8.2. See the changelog for this version here, and the associated pull request PR#27334. Update to at least this version to fix the problem.