Skip to content

Commit 28ec5bd

Browse files
committed
Fix annotation position
1 parent 23afcb4 commit 28ec5bd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/lines_bars_and_markers/linestyles.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import matplotlib.pyplot as plt
66
from collections import OrderedDict
7+
from matplotlib.transforms import blended_transform_factory
78

89
linestyles = OrderedDict(
910
[('solid', (0, ())),
@@ -35,9 +36,13 @@
3536
plt.yticks(np.arange(len(linestyles)), linestyles.keys())
3637
plt.xticks([])
3738

39+
# For each line style, add a text annotation with a small offset from
40+
# the reference point (0 in Axes coords, y tick value in Data coords).
41+
reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
3842
for i, (name, linestyle) in enumerate(linestyles.items()):
39-
ax.text(-0.5, i-0.4, str(linestyle), fontsize=8, ha="right",
40-
color="blue", family="monospace")
43+
ax.annotate(str(linestyle), xy=(0.0, i), xycoords=reference_transform,
44+
xytext=(-6, -12), textcoords='offset points', color="blue",
45+
fontsize=8, ha="right", family="monospace")
4146

4247
plt.tight_layout()
4348
plt.show()

0 commit comments

Comments
 (0)