Skip to content

Text ignores rotational part of transformation #698

Closed
@stefanv

Description

@stefanv

When specifying a transformation to plt.text, the rotational part of the transformation is ignored. I'm aware of the rotation keyword, but in my use case, I need some more fine-grained control.

Here's an example, in which a box and text receives the same transformation, but displays differently:

from matplotlib import patches, transforms
import matplotlib.pyplot as plt
import numpy as np

ax = plt.gca()

theta = np.deg2rad(30)
S = np.sin(theta)
C = np.cos(theta)
R = transforms.Affine2D(matrix=np.array([[ C, -S, 0.5],
                                         [ S,  C, 0.5],
                                         [ 0,  0, 1.]]))

rect = patches.Rectangle((0, 0), 0.5, 0.1, transform=R + ax.transData)
text = plt.text(0, 0, 'hello', size=50, transform=R + ax.transData)

ax.add_patch(rect)

plt.show()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions