Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib styles mess with placement #190

Open
skwde opened this issue Dec 25, 2024 · 0 comments
Open

matplotlib styles mess with placement #190

skwde opened this issue Dec 25, 2024 · 0 comments

Comments

@skwde
Copy link

skwde commented Dec 25, 2024

I also asked this on stackoverflow (https://stackoverflow.com/questions/79303139/maptloblib-adjust-text-and-errorbar).
Due to a comment I tried again and found that there is a problem occuring only when matplotlib styles are used.

See following example:

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scienceplots  # type: ignore
from adjustText import adjust_text

plt.style.use(["science", "notebook"])

fig, ax = plt.subplots()

x = np.linspace(0, 1, 50) * np.pi
y = np.sin(x)

errbar_container = ax.errorbar(x, y, xerr=0.25, yerr=0.05)

texts = []
for idx in range(0, len(x),2):
    texts.append(
        ax.annotate(
            idx,
            xy=(x[idx], y[idx]),
            size="large",
            zorder=100,
        )
    )

adjust_text(
    texts,
    x=x,
    y=y,
    expand=(2, 2),
    objects=[
        *[mpl.transforms.Bbox(seg) for seg in errbar_container.lines[-1][0].get_segments()],
        *[mpl.transforms.Bbox(seg) for seg in errbar_container.lines[-1][1].get_segments()],
    ],
    arrowprops=dict(arrowstyle="->", color="red"),
)

plt.show()

which produces following plot:

image

Note how 0, 2 and 4 plotted on the line.

Moreover it seems that option like autoalign, only_move are ignored.

Without plt.style.use(["science", "notebook"]) everything looks fine.

So what am I missing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant