|
19 | 19 |
|
20 | 20 | fig, ax = plt.subplots() |
21 | 21 |
|
22 | | -# Plot diagonal line (45 degrees) |
23 | | -h = ax.plot(range(0, 10), range(0, 10)) |
24 | | - |
25 | | -# set limits so that it no longer looks on screen to be 45 degrees |
26 | | -ax.set_xlim([-10, 20]) |
27 | | - |
28 | | -# Locations to plot text |
29 | | -l1 = np.array((1, 1)) |
30 | | -l2 = np.array((5, 5)) |
31 | | - |
32 | | -# Rotate angle |
33 | | -angle = 45 |
| 22 | +# Plot diagonal line (45 degrees in data coordinates) |
| 23 | +ax.plot(range(0, 8), range(0, 8)) |
| 24 | +ax.set_xlim([-10, 10]) |
34 | 25 |
|
35 | 26 | # Plot text |
36 | | -th1 = ax.text(*l1, 'text not rotated correctly', fontsize=16, |
37 | | - rotation=angle, rotation_mode='anchor') |
38 | | -th2 = ax.text(*l2, 'text rotated correctly', fontsize=16, |
39 | | - rotation=angle, rotation_mode='anchor', |
40 | | - transform_rotates_text=True) |
| 27 | +ax.text(-8, 0, 'text 45° in screen coordinates', fontsize=18, |
| 28 | + rotation=45, rotation_mode='anchor') |
| 29 | +ax.text(0, 0, 'text 45° in data coordinates', fontsize=18, |
| 30 | + rotation=45, rotation_mode='anchor', |
| 31 | + transform_rotates_text=True) |
41 | 32 |
|
42 | 33 | plt.show() |
0 commit comments