Hello,
A very helpful tool! All works great when I work with text objects alone. I run into troubles after asking for a bit more complex task.
I would like to use adjust_text to avoid a set of lines that I draw using vlines. When I take the output and turn it into PathCollection object I run into errors. It could be that I just don't know how to use PathCollection.
I am using matplotlib 3.9.2 and python 3.12.3.
An example:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from adjustText import adjust_text
# prepare input
npeaks = 10
xs = np.linspace(0, 1, npeaks)
rng = np.random.default_rng(seed=1)
heights = rng.random(size=npeaks)
# plot stems
fig, ax = plt.subplots(figsize=(3, 3))
vlines: mpl.collections.LineCollection = ax.vlines(xs, heights, 0.0)
# add texts
texts = list()
for x, y in zip(xs, heights):
text = ax.text(x, y/2, "note", ha='center', va='center')
texts += [text]
# turn the LineCollection into a PathCollection
path_list: list[mpl.path.Path] = vlines.get_paths()
print(f"{path_list[0]=}")
pathcoll = mpl.collections.PathCollection(path_list)
print(f"{pathcoll=}")
adjust_text(texts, objects=pathcoll)
plt.show()
Thanks
Pawel
Hello,
A very helpful tool! All works great when I work with text objects alone. I run into troubles after asking for a bit more complex task.
I would like to use
adjust_textto avoid a set of lines that I draw usingvlines. When I take the output and turn it intoPathCollectionobject I run into errors. It could be that I just don't know how to usePathCollection.I am using matplotlib 3.9.2 and python 3.12.3.
An example:
Thanks
Pawel