'Contour label rotation wrong when using manual positioning in matplotlib

I am adding label at certain positions on a contour plot in matplotlib. As describe in the documentaion, when using the manual=true parameter, I can place the label and everything seems fine (see 1st plot below) but when entering the possitions of those labels in the code directly as manual=[(x0,y0), (x1,y1), etc.] the rotation of the labels seems to go wrong for some reason (2nd plot). enter image description here

I can't figure out why it not the same behavior in both cases unlike what is mentionned in the documentation or is it a bug?

Documentation

manual can also be an iterable object of (x, y) tuples. Contour labels will be created as if mouse is clicked at each (x, y) position.

Here is the code to generate it. Note on the bottom manual=True or manual=positions.

import numpy as np
import matplotlib.pyplot as plt


delta = 0.01
x = np.arange(75, 300+delta, delta)
y = np.arange(1.75, 4.01, delta)
X, Y = np.meshgrid(x, y)
Z = X*Y

fig, ax = plt.subplots()
levels = [150, 250, 300, 350, 450, 500, 550, 650, 700, 750, 850, 900, 950, 1050, 1100, 1150]
ax.contour(X, Y, Z, levels=levels, colors='k', linewidths=0.1)
CS = ax.contour(X, Y, Z, 5, colors='k', linewidths=0.5)

ax.set_xlabel("Capacity (mAh/g)", fontsize=12)
ax.set_ylabel(r'Average voltage (V vs. ${Li^{+}/Li}$)', fontsize=12)

# Square graph
aspect = (x.max()-x.min())/(y.max()-y.min())
ax.set_aspect(aspect)

plt.tight_layout()

positions = [(94,2.122), (157,2.54), (206,2.915), (244,3.29), (273,3.66)]
ax.clabel(CS, inline=True, fontsize=12, fmt='%1.f Wh/kg', manual=True) # or manual=positions

plt.show()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source