С помощью matplotlib я создаю фигуру, содержащую два объекта Axes (, т. е. два набора ху -оси ). Я хочу соединить две точки ---, одна из которых выбрана на одной из осей, а другая — на другой оси ---стрелкой или линией.
Я попытался сделать это с помощью функции annotate ()и объекта ConnectionPatch, но в обоих случаях часть стрелки была скрыта «рамкой» оси. Пожалуйста, смотрите прикрепленный рисунок, на котором я пытался соединить происхождение двух осей с помощью объекта ConnectionPatch.
Я также прилагаю скрипт, используемый для создания рисунка.
Есть ли способ «выдвинуть» стрелку (или отодвинуть осевую рамку назад )?
#!/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')