-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Bug summary
Despite being documented [here] and (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.annotate.html)
here, providing ShinkA and ShrinkB are ignored in annotations.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.linspace(0, 10, 100)
y = np.sin(x)
ax.plot(x, y)
# Annotate a some points with varying shrinkA values
annotation_x_values = [3,4,5,6,7]
shrinkA_values = [0, 0.2, 0.4, 0.6, 0.8]
for shrinkA, x_anno in zip(shrinkA_values, annotation_x_values):
y_anno = np.sin(x_anno)
ax.annotate(
f'shrinkA={shrinkA}',
xy=(x_anno, y_anno),
xytext=(x_anno+1, y_anno+0.2),
arrowprops=dict(arrowstyle="->", shrinkA=shrinkA),
fontsize=10
)
plt.tight_layout()
plt.show()
Actual outcome
All the arrows in the example above look the same; ShinkA/ShrinkB has no effect.
Expected outcome
Expected that the beginning / end of the arrows are moved toward or away from the source/target of the arrow.
By way of example, the simplearrow shrink=
parameter (when arrowstyle
is omitted) works as expected:
Click here to expand code to reproduce the image below
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(5, 3))
x = np.linspace(0, 10, 100)
y = np.sin(x)
ax.plot(x, y)
# Annotate a some points with varying shrinkA values
annotation_x_values = [3,4,5,6,7]
shrink_values = [0, 0.2, 0.4, 0.6, 0.8]
for shrink, x_anno in zip(shrink_values, annotation_x_values):
y_anno = np.sin(x_anno)
ax.annotate(
f'shrink={shrink}',
xy=(x_anno, y_anno),
xytext=(x_anno+1, y_anno+0.2),
arrowprops=dict(shrink=shrink),
fontsize=10
)
plt.tight_layout()
plt.show()
However then I cant use the desired arrowstyle='-->'
or control which end of the arrow is shrunk.
Additional information
I have not been able to confirm, but I belive this comment from the documentation for FancyArrowPatch
is the likely cause (link to doc source).
Alternatively if *path* is provided, an arrow is drawn along this path and *patchA*, *patchB*, *shrinkA*, and *shrinkB* are ignored.
My guess was that in the implementation of Axes.annotate, the *path*
is provided?
I cant find if that is happening though.
I think debugging near this use set_positions() might be a good starting point?
Operating system
windows
Matplotlib Version
3.8.3
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
Python 3.11.5
Jupyter version
VS Code Notebook (ipython Version: 8.17.2)
Installation
pip