Given the following code:
fig, ax = plt.subplots()
ax.scatter([1, 2, 3, 4, 5], [34, 22, 11, 4, 6], s=100)
_ = ax.text(x=0, y=1.1, s="This is some text", transform=ax.transAxes, fontsize=20)
rect = mpl.patches.Rectangle(
(0.5, 0.5), width=0.05, height=0.05, color="red", transform=ax.transAxes,
)
ax.add_patch(rect)
Which creates:
I would like to add the patch to the following location:
So that the plot looks as follows:
It seems that I am unable to have patches outside of the axes spines area though, for example the following code:
fig, ax = plt.subplots()
ax.scatter([1, 2, 3, 4, 5], [34, 22, 11, 4, 6], s=100)
_ = ax.text(x=0, y=1.1, s="This is some text", transform=ax.transAxes, fontsize=20)
rect = mpl.patches.Rectangle(
(0.5, 0.5), width=0.05, height=0.5, color="red", transform=ax.transAxes,
)
ax.add_patch(rect)
gives
Looking in the method for matplotlib.figure.Figure I can't see anything for add_patch
['_clippath',
'_path_effects',
'get_clip_path',
'get_path_effects',
'get_transformed_clip_path_and_affine',
'patch',
'patches',
'set_clip_path',
'set_path_effects']
The above are the methods with pat in them.




