Skip to content

Simplify some annotation() calls in examples. #13549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/lines_bars_and_markers/linestyles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.transforms import blended_transform_factory

linestyle_str = [
('solid', 'solid'), # Same as (0, ()) or '-'
('solid', 'solid'), # Same as (0, ()) or '-'
('dotted', 'dotted'), # Same as (0, (1, 1)) or '.'
('dashed', 'dashed'), # Same as '--'
('dashdot', 'dashdot')] # Same as '-.'
Expand Down Expand Up @@ -55,11 +54,11 @@ def plot_linestyles(ax, linestyles):

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


fig, (ax0, ax1) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 3]},
Expand Down
4 changes: 2 additions & 2 deletions examples/pie_and_polar_charts/pie_and_donut_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def func(pct, allvals):
wedges, texts = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)

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

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

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

Expand Down
6 changes: 2 additions & 4 deletions examples/showcase/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ def text(x, y, text):
text(-0.3, 0.45, "Figure")

color = 'blue'
ax.annotate('Spines', xy=(4.0, 0.35), xycoords='data',
xytext=(3.3, 0.5), textcoords='data',
ax.annotate('Spines', xy=(4.0, 0.35), xytext=(3.3, 0.5),
weight='bold', color=color,
arrowprops=dict(arrowstyle='->',
connectionstyle="arc3",
color=color))

ax.annotate('', xy=(3.15, 0.0), xycoords='data',
xytext=(3.45, 0.45), textcoords='data',
ax.annotate('', xy=(3.15, 0.0), xytext=(3.45, 0.45),
weight='bold', color=color,
arrowprops=dict(arrowstyle='->',
connectionstyle="arc3",
Expand Down
4 changes: 2 additions & 2 deletions examples/style_sheets/style_sheets_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def plot_histograms(ax, prng, nb_samples=10000):
ax.hist(values, histtype="stepfilled", bins=30,
alpha=0.8, density=True)
# Add a small annotation.
ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data',
xytext=(0.9, 0.9), textcoords='axes fraction',
ax.annotate('Annotation', xy=(0.25, 4.25),
xytext=(0.9, 0.9), textcoords=ax.transAxes,
va="top", ha="right",
bbox=dict(boxstyle="round", alpha=0.2),
arrowprops=dict(
Expand Down
8 changes: 3 additions & 5 deletions examples/text_labels_and_annotations/mathtext_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def doall():
full_demo = mathext_demos[0]
plt.annotate(full_demo,
xy=(0.5, 1. - 0.59 * line_axesfrac),
xycoords='data', color=mpl_orange_rvb, ha='center',
fontsize=20)
color=mpl_orange_rvb, ha='center', fontsize=20)

# Plotting features demonstration formulae
for i_line in range(1, n_lines):
Expand All @@ -92,12 +91,11 @@ def doall():
color=fill_color, alpha=0.5)
plt.annotate(title,
xy=(0.07, baseline - 0.3 * line_axesfrac),
xycoords='data', color=mpl_grey_rvb, weight='bold')
color=mpl_grey_rvb, weight='bold')
demo = mathext_demos[i_line]
plt.annotate(demo,
xy=(0.05, baseline - 0.75 * line_axesfrac),
xycoords='data', color=mpl_grey_rvb,
fontsize=16)
color=mpl_grey_rvb, fontsize=16)

for i in range(n_lines):
s = mathext_demos[i]
Expand Down
3 changes: 1 addition & 2 deletions examples/text_labels_and_annotations/usetex_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
shadow=True, loc=(0.01, 0.48), handlelength=1.5, fontsize=16)

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