10000 Merge pull request #7346 from afvincent/fix_linestyles_example · matplotlib/matplotlib@0030e7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0030e7a

Browse files
committed
Merge pull request #7346 from afvincent/fix_linestyles_example
DOC: Fix annotation position (issue #7345)
1 parent b1af052 commit 0030e7a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/lines_bars_and_markers/linestyles.py

Lines changed: 7 additions & 2 deletions
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)
0