Skip to content

Commit 12bad8f

Browse files
committed
Simplify some annotation() calls in examples.
1 parent 2208665 commit 12bad8f

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

examples/lines_bars_and_markers/linestyles.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
"""
1717
import numpy as np
1818
import matplotlib.pyplot as plt
19-
from matplotlib.transforms import blended_transform_factory
2019

2120
linestyle_str = [
22-
('solid', 'solid'), # Same as (0, ()) or '-'
21+
('solid', 'solid'), # Same as (0, ()) or '-'
2322
('dotted', 'dotted'), # Same as (0, (1, 1)) or '.'
2423
('dashed', 'dashed'), # Same as '--'
2524
('dashdot', 'dashdot')] # Same as '-.'
@@ -55,11 +54,11 @@ def plot_linestyles(ax, linestyles):
5554

5655
# For each line style, add a text annotation with a small offset from
5756
# the reference point (0 in Axes coords, y tick value in Data coords).
58-
reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
5957
for i, (name, linestyle) in enumerate(linestyles):
60-
ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=reference_transform,
61-
xytext=(-6, -12), textcoords='offset points', color="blue",
62-
fontsize=8, ha="right", family="monospace")
58+
ax.annotate(repr(linestyle),
59+
xy=(0.0, i), xycoords=ax.get_yaxis_transform(),
60+
xytext=(-6, -12), textcoords='offset points',
61+
color="blue", fontsize=8, ha="right", family="monospace")
6362

6463

6564
fig, (ax0, ax1) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 3]},

examples/pie_and_polar_charts/pie_and_donut_labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def func(pct, allvals):
102102
wedges, texts = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)
103103

104104
bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
105-
kw = dict(xycoords='data', textcoords='data', arrowprops=dict(arrowstyle="-"),
105+
kw = dict(arrowprops=dict(arrowstyle="-"),
106106
bbox=bbox_props, zorder=0, va="center")
107107

108108
for i, p in enumerate(wedges):
@@ -113,7 +113,7 @@ def func(pct, allvals):
113113
connectionstyle = "angle,angleA=0,angleB={}".format(ang)
114114
kw["arrowprops"].update({"connectionstyle": connectionstyle})
115115
ax.annotate(recipe[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.4*y),
116-
horizontalalignment=horizontalalignment, **kw)
116+
horizontalalignment=horizontalalignment, **kw)
117117

118118
ax.set_title("Matplotlib bakery: A donut")
119119

examples/showcase/anatomy.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ def text(x, y, text):
125125
text(-0.3, 0.45, "Figure")
126126

127127
color = 'blue'
128-
ax.annotate('Spines', xy=(4.0, 0.35), xycoords='data',
129-
xytext=(3.3, 0.5), textcoords='data',
128+
ax.annotate('Spines', xy=(4.0, 0.35), xytext=(3.3, 0.5),
130129
weight='bold', color=color,
131130
arrowprops=dict(arrowstyle='->',
132131
connectionstyle="arc3",
133132
color=color))
134133

135-
ax.annotate('', xy=(3.15, 0.0), xycoords='data',
136-
xytext=(3.45, 0.45), textcoords='data',
134+
ax.annotate('', xy=(3.15, 0.0), xytext=(3.45, 0.45),
137135
weight='bold', color=color,
138136
arrowprops=dict(arrowstyle='->',
139137
connectionstyle="arc3",

examples/style_sheets/style_sheets_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def plot_histograms(ax, prng, nb_samples=10000):
9191
ax.hist(values, histtype="stepfilled", bins=30,
9292
alpha=0.8, density=True)
9393
# Add a small annotation.
94-
ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data',
95-
xytext=(0.9, 0.9), textcoords='axes fraction',
94+
ax.annotate('Annotation', xy=(0.25, 4.25),
95+
xytext=(0.9, 0.9), textcoords=ax.transAxes,
9696
va="top", ha="right",
9797
bbox=dict(boxstyle="round", alpha=0.2),
9898
arrowprops=dict(

examples/text_labels_and_annotations/mathtext_examples.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def doall():
7878
full_demo = mathext_demos[0]
7979
plt.annotate(full_demo,
8080
xy=(0.5, 1. - 0.59 * line_axesfrac),
81-
xycoords='data', color=mpl_orange_rvb, ha='center',
82-
fontsize=20)
81+
color=mpl_orange_rvb, ha='center', fontsize=20)
8382

8483
# Plotting features demonstration formulae
8584
for i_line in range(1, n_lines):
@@ -92,12 +91,11 @@ def doall():
9291
color=fill_color, alpha=0.5)
9392
plt.annotate(title,
9493
xy=(0.07, baseline - 0.3 * line_axesfrac),
95-
xycoords='data', color=mpl_grey_rvb, weight='bold')
94+
color=mpl_grey_rvb, weight='bold')
9695
demo = mathext_demos[i_line]
9796
plt.annotate(demo,
9897
xy=(0.05, baseline - 0.75 * line_axesfrac),
99-
xycoords='data', color=mpl_grey_rvb,
100-
fontsize=16)
98+
color=mpl_grey_rvb, fontsize=16)
10199

102100
for i in range(n_lines):
103101
s = mathext_demos[i]

examples/text_labels_and_annotations/usetex_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
shadow=True, loc=(0.01, 0.48), handlelength=1.5, fontsize=16)
2626

2727
# the arrow
28-
plt.annotate("", xy=(-delta / 2., 0.1), xycoords='data',
29-
xytext=(delta / 2., 0.1), textcoords='data',
28+
plt.annotate("", xy=(-delta / 2., 0.1), xytext=(delta / 2., 0.1),
3029
arrowprops=dict(arrowstyle="<->", connectionstyle="arc3"))
3130
plt.text(0, 0.1, r'$\delta$',
3231
{'color': 'black', 'fontsize': 24, 'ha': 'center', 'va': 'center',

0 commit comments

Comments
 (0)