Connect a point on an axis and another point on another axis with an arrow in matplotlib

With matplotlib, I make a shape containing two Axes objects (i.e. two sets of xy-axes). I want to connect two points - one selected from one of the axes, and the other selected from the other axis - an arrow or a line.

I tried to do this using the annotate () function and the ConnectionPatch object, but in both directions, part of the arrow was hidden by the "frame" of the axis. See the attached figure, in which I tried to relate the origin of two axes using the ConnectionPatch object.

I also attach the script used to create the shape.

Is there a way to β€œextend” the arrow (or move the axis frame back)?

Trying to connect the origins of the two axes.

#!/usr/bin/python
# 
# This script was written by Norio TAKEMOTO 2012-5-7


import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch

# creating a figure and axes.
fig=plt.figure(figsize=(10,5))

ax1=plt.axes([0.05,0.15,0.40,0.80])

plt.xticks([0])
plt.yticks([0])
plt.xlim((-1.23, 1.23))
plt.ylim((-2.34, 2.34))


ax2=plt.axes([0.60,0.15, 0.30, 0.30])

plt.xticks([0])
plt.yticks([0])
plt.xlim((-3.45, 3.45))
plt.ylim((-4.56, 4.56))


# trying to connect the point (0,0) in ax1 and the point (0,0) in ax2
# by an arrow, but some part is hidden. I can't find a solution. Let's
# ask stackoverflow.

#xy_A_ax1=(0,0)
#xy_B_ax2=(0,0)
#
#inv1 = ax1.transData.inverted()
#xy_B_display = ax2.transData.transform(xy_B_ax2)
#xy_B_ax1     = inv1.transform(xy_B_display)
#ax1.annotate('Wundaba', xy=(0, 0), xytext=xy_B_ax1,
#             xycoords='data',textcoords='data', 
#             arrowprops=dict(arrowstyle='->'))


con = ConnectionPatch(xyA=(0, 0), xyB=(0, 0), 
                      coordsA='data', coordsB='data', 
                      axesA=ax1, axesB=ax2,
                      arrowstyle='->', clip_on=False)
ax1.add_artist(con)

plt.savefig('fig1.eps')
plt.savefig('fig1.png')
+3
source share
1 answer

- savefig(), .. plt.savefig('fig1.png', transparent=1):

enter image description here

:

ax2.patch.set_facecolor('None')

21.

+3

All Articles