3

I have a graph in Matplotlib that looks like this:

enter image description here

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:

sf

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?

  • Indeed you need to decide if you want to transform your text to 2D first and then skew, or if you want to place it in 3D and let the matplotlib transform do it for you. In any case you cannot use the text itself, but need to convert it to a `Path` first. Search for `TextPath` for that matter. – ImportanceOfBeingErnest Aug 08 '19 at 18:54

0 Answers0