Skip to content

Commit

Permalink
Merge 66ae705 into c7e3217
Browse files Browse the repository at this point in the history
  • Loading branch information
darribas committed Aug 1, 2019
2 parents c7e3217 + 66ae705 commit 708e099
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions contextily/plotting.py
Expand Up @@ -179,13 +179,17 @@ def add_attribution(ax, att=ATTRIBUTION, font_size=ATTRIBUTION_SIZE):
Matplotlib axis with `x_lim` and `y_lim` set in Web
Mercator (EPSG=3857) and attribution text added
"""
minX, maxX = ax.get_xlim()
minY, maxY = ax.get_ylim()
ax.text(
minX + (maxX - minX) * 0.005,
minY + (maxY - minY) * 0.005,
txt = ax.text(
0.005,
0.005,
att,
transform=ax.transAxes,
size=font_size,
path_effects=[patheffects.withStroke(linewidth=2, foreground="w")],
wrap=True,
)
# hack to have the text wrapped in the ax extent, for some explanation see
# https://stackoverflow.com/questions/48079364/wrapping-text-not-working-in-matplotlib
wrap_width = ax.get_window_extent().width * 0.99
txt._get_wrap_line_width = lambda: wrap_width
return ax

0 comments on commit 708e099

Please sign in to comment.