Skip to content

Commit 96796d8

Browse files
authored
Merge pull request #7346 from afvincent/fix_linestyles_example
DOC: Fix annotation position (issue #7345)
2 parents 23afcb4 + 28ec5bd commit 96796d8

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy