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:

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?
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:
which produces following plot:
Note how
0,2and4plotted on the line.Moreover it seems that option like
autoalign,only_moveare ignored.Without
plt.style.use(["science", "notebook"])everything looks fine.So what am I missing here?