Skip to content

Instantly share code, notes, and snippets.

@nbigaouette
Created October 15, 2012 16:31
Show Gist options
  • Save nbigaouette/3893442 to your computer and use it in GitHub Desktop.
Save nbigaouette/3893442 to your computer and use it in GitHub Desktop.
Matplotlib arrow (annotate) bug (#1402)
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
fig1 = plt.figure()
ax1 = fig1.add_subplot(221)
ax2 = fig1.add_subplot(222)
ax3 = fig1.add_subplot(223)
ax4 = fig1.add_subplot(224)
axes = [ax1, ax2, ax3, ax4]
r0 = [0.5, 0.0]
r1 = [0.5, 1.0]
ylims = [( 0.0, 1.0),
(-0.5, 1.5),
( 0.5, 1.5),
(-0.5, 0.5)]
for i in xrange(len(axes)):
ax = axes[i]
ann = ax.annotate('', xy = (r1[0], r1[1]), xycoords='data',
xytext = (r0[0], r0[1]), textcoords='data',
arrowprops=dict(arrowstyle="-|>"),
annotation_clip=False)
ann.arrow_patch.set_clip_box(ax.bbox)
ax.set_xlim(( 0.0, 1.0))
ax.set_ylim(ylims[i])
ax.text(0.6, 0.5, str(ylims[i]), transform=ax.transAxes)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment