0

As per the block of code below, using ax.annotate() it appears that the outer extents of the Figure object are not properly captured by figure fraction. I would expect the arrows to point right to the very corners of the plot, which as per first plot they do not.

Also when the figure plot is created without any of the annotations, it is not the same size - see second plot. The annotations I've used should not change the figure size. I'm using info from this Matplotlib page.

Anyone able to explain these oddities?

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.axis([0, 10, 0, 10])
bbox_args = dict(boxstyle="round, pad=0.3", fc="w", ec='red', alpha=0.5)
arrow_args = dict(arrowstyle="->")

# figure fraction
ax.annotate('figure fraction : 0, 0', xy=(0, 0),  xycoords='figure fraction', xytext=(20, 20), 
            textcoords='offset points', ha='left', va='bottom', bbox=bbox_args,
            arrowprops=arrow_args)
ax.annotate('figure fraction : 1, 1', xy=(1, 1),  xycoords='figure fraction', xytext=(-20, -10), 
            textcoords='offset points', ha='right', va='top', bbox=bbox_args,
            arrowprops=arrow_args)

# axes fraction
ax.annotate('axes fraction : 0, 0', xy=(0, 0), xycoords='axes fraction',
             xytext=(20, 20), textcoords='offset points',
             ha="left", va="bottom", bbox=bbox_args,
             arrowprops=arrow_args)
ax.annotate('axes fraction : 1, 1', xy=(1, 1), xycoords='axes fraction',
             xytext=(-20, -20), textcoords='offset points',
             ha="right", va="top", bbox=bbox_args,
             arrowprops=arrow_args)

first plot

When no annotations are included i.e. just:

fig, ax = plt.subplots()
ax.axis([0, 10, 0, 10])

second plot

henrybish
  • 3
  • 3
  • What version of Matplotlib are you using? Running in the latest version (3.6.3), I find that the upper right figure fraction arrow does point right to the corner unlike your image. – Matt Pitkin Jan 30 '23 at 14:53
  • Yes, I'm also running matplotlib 3.6.3. I'm using it with Spyder 5.4.2 IDE, with latest version of matplotlib-inline 0.1.6. The same issue exists whether I plot inline or not. – henrybish Jan 30 '23 at 17:03

0 Answers0