Skip to content

[Bug]: ShrinkA and ShrinkB are ignored in ax.annotate(arrowprops=...) #27941

@thehappycheese

Description

@thehappycheese

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.
image

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()

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy