Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Backport PR #29621: DOC: Cleanup text rotation in data coordinates ex…
…ample
  • Loading branch information
rcomer authored and meeseeksmachine committed Feb 14, 2025
commit 6314d30e4cad3b0437ad10b85b8bf5eff64f7f44
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,18 @@
"""

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()

# Plot diagonal line (45 degrees)
h = ax.plot(range(0, 10), range(0, 10))

# set limits so that it no longer looks on screen to be 45 degrees
ax.set_xlim([-10, 20])

# Locations to plot text
l1 = np.array((1, 1))
l2 = np.array((5, 5))

# Rotate angle
angle = 45
# Plot diagonal line (45 degrees in data coordinates)
ax.plot(range(0, 8), range(0, 8))
ax.set_xlim([-10, 10])

# Plot text
th1 = ax.text(*l1, 'text not rotated correctly', fontsize=16,
rotation=angle, rotation_mode='anchor')
th2 = ax.text(*l2, 'text rotated correctly', fontsize=16,
rotation=angle, rotation_mode='anchor',
transform_rotates_text=True)
ax.text(-8, 0, 'text 45° in screen coordinates', fontsize=18,
rotation=45, rotation_mode='anchor')
ax.text(0, 0, 'text 45° in data coordinates', fontsize=18,
rotation=45, rotation_mode='anchor',
transform_rotates_text=True)

plt.show()