I have a graph in Matplotlib that looks like this:
I would like to skew the text (by an x-shear of 10.3 and a y shear of 9.0) in order to make it appear to be parallel with the bars. Here is my code that I am using:
_x = [0,1,2,3]
_y = [1, 2]
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = [1, 0, 0, 3, 0, 0, 0, 0]
bottom = np.zeros_like(top)
width = 1
depth = 0.25
# graph is set up here
for i, iXZ in enumerate(zip(x, top)):
iX, iZ = iXZ
if iZ:
t = ax1.text(iX + 0.5, 1, -0.85, ('U\n' if i == 0 else 'E\n') * iZ, (0, 0, 0),
ha='center', va='bottom', fontfamily="Century Gothic", color='black', fontsize=40)
# skew by 10.3 and 9.0
t.set_transform(mtrns.CompositeGenericTransform(t.get_transform(), mtrns.Affine2D().skew(10.3, 9.0)))
However, when this code is run, matplotlib outputs this:
I feel like I am using the wrong type of transform, since Affine2D
implies that it's only for "2D" objects. Unfortunately, I cannot find the "right" method in the documentation. How would I be able to skew the text effectively?