adjustText icon indicating copy to clipboard operation
adjustText copied to clipboard

adjust_text weirdly changed the y_position of the points into a dense cluster.

Open DiyuanLu opened this issue 2 years ago • 7 comments

python 3.9 Macbook Pro M2 2022 pycharm

plt.figure()
x = np.random.randn(30)
y = np.random.randn(30)
plt.scatter(x, y)
texts = [plt.text(x_pos, y_pos, f"position-{ele:.2f}") for (x_pos, y_pos, ele) in zip(x, y, x)]

a toy example to generate overlapping text before: image after: image

plt.figure()
x = np.random.randn(30)
y = np.random.randn(30)
plt.scatter(x, y)
texts = [plt.text(x_pos, y_pos, f"position-{ele:.2f}") for (x_pos, y_pos, ele) in zip(x, y, x)]
adjust_text(texts, arrowprops=dict(arrowstyle="->", color='r', lw=0.5))

no sure what went wrong. Thanks for any feedback in advance.

DiyuanLu avatar Mar 09 '23 16:03 DiyuanLu

I am sorry, I can't reproduce this... Neither with the latest release, not with the latest version on master. I get something reasonable like this image

Phlya avatar Mar 09 '23 16:03 Phlya

it seems it is somehow not compatible with some packages in my conda environment. I tried the code in a base environment, where it only has a few basic packages installed, and it worked. But it kept producing the weird effect in my conda environment. my environment has the following packages

Package                  Version
------------------------ -----------
absl-py                  1.2.0
adjustText               0.8
aiohttp                  3.8.4
aiosignal                1.3.1
anndata                  0.8.0
annoy                    1.17.1
anyio                    3.6.2
appdirs                  1.4.4
appnope                  0.1.3
argon2-cffi              21.3.0
argon2-cffi-bindings     21.2.0
arrow                    1.2.2
asttokens                2.0.8
astunparse               1.6.3
async-timeout            4.0.2
attrs                    22.1.0
backcall                 0.2.0
beautifulsoup4           4.11.1
bhtsne                   0.1.9
bioinfokit               2.1.0
biomart                  0.9.2
biopython                1.81
bleach                   5.0.1
bokeh                    2.4.3
bravado                  11.0.3
bravado-core             5.17.0
cached-property          1.5.2
cachetools               5.2.0
certifi                  2022.6.15
cffi                     1.15.1
charset-normalizer       2.1.1
click                    8.1.3
cloudpickle              2.2.1
comtypes                 1.1.14
cycler                   0.11.0
Cython                   0.29.32
dask                     2023.2.0
datacache                1.1.5
datasets                 2.9.0
debugpy                  1.6.3
decorator                5.1.1
defusedxml               0.7.1
dill                     0.3.6
docker-pycreds           0.4.0
entrypoints              0.4
et-xmlfile               1.1.0
etils                    0.9.0
executing                1.1.1
fastjsonschema           2.16.2
filelock                 3.9.0
flatbuffers              1.12
fonttools                4.36.0
fqdn                     1.5.1
frozenlist               1.3.3
fsspec                   2023.1.0
gast                     0.4.0
gitdb                    4.0.10
GitPython                3.1.31
google-auth              2.11.0
google-auth-oauthlib     0.4.6
google-pasta             0.2.0
googleapis-common-protos 1.56.4
grpcio                   1.48.0
gseapy                   0.14.0
gtfparse                 1.2.1
h5py                     3.6.0
huggingface-hub          0.12.1
idna                     3.3
imbalanced-learn         0.9.1
importlib-metadata       4.12.0
importlib-resources      5.10.0
iniconfig                1.1.1
ipykernel                6.16.1
ipython                  8.5.0
ipython-genutils         0.2.0
ipywidgets               8.0.2
isoduration              20.11.0
jedi                     0.18.1
Jinja2                   3.1.2
joblib                   1.1.0
jsonpointer              2.3
jsonref                  0.2
jsonschema               4.14.0
jupyter                  1.0.0
jupyter_client           7.4.3
jupyter-console          6.4.4
jupyter_core             4.11.2
jupyter-server           1.21.0
jupyterlab-pygments      0.2.2
jupyterlab-widgets       3.0.3
keras                    2.9.0
Keras-Preprocessing      1.1.2
kiwisolver               1.4.4
kneed                    0.8.1
libclang                 14.0.6
llvmlite                 0.39.0
locket                   1.0.0
Markdown                 3.4.1
MarkupSafe               2.1.1
matplotlib               3.5.3
matplotlib-inline        0.1.6
matplotlib-venn          0.11.7
memoized-property        1.0.3
mistune                  2.0.4
mock                     4.0.3
monotonic                1.6
msgpack                  1.0.4
multidict                6.0.4
multiprocess             0.70.14
munkres                  1.1.4
natsort                  8.2.0
nbclassic                0.4.5
nbclient                 0.7.0
nbconvert                7.2.2
nbformat                 5.7.0
ncafs                    0.2
nest-asyncio             1.5.6
networkx                 3.0
notebook                 6.5.1
notebook_shim            0.2.0
numba                    0.56.0
numpy                    1.22.4
oauthlib                 3.2.0
opencv-python            4.7.0.68
openpyxl                 3.0.10
opt-einsum               3.3.0
packaging                21.3
pacmap                   0.6.5
pandas                   1.4.3
pandocfilters            1.5.0
parso                    0.8.3
partd                    1.3.0
pathtools                0.1.2
patsy                    0.5.3
pexpect                  4.8.0
pickleshare              0.7.5
Pillow                   9.2.0
pip                      22.2.2
plastid                  0.6.1
pluggy                   1.0.0
progressbar33            2.4
prometheus-client        0.15.0
promise                  2.3
prompt-toolkit           3.0.31
protobuf                 3.19.4
psutil                   5.9.3
ptyprocess               0.7.0
pure-eval                0.2.2
py                       1.11.0
pyarrow                  11.0.0
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pycparser                2.21
pyEDFlib                 0.1.30
pyensembl                2.0.1
Pygments                 2.13.0
pynndescent              0.5.7
pyoncoprint              0.2.2
pyparsing                3.0.9
pyrsistent               0.18.1
pysam                    0.20.0
pytest                   7.1.3
pyts                     0.12.0
pytz                     2022.2.1
PyYAML                   6.0
pyzmq                    24.0.1
qtconsole                5.3.2
QtPy                     2.2.1
requests                 2.28.1
requests-oauthlib        1.3.1
responses                0.18.0
rfc3339-validator        0.1.4
rfc3987                  1.3.8
rsa                      4.9
scanpy                   1.9.1
scikit-allel             1.3.5
scikit-learn             1.1.2
scikit-plot              0.3.7
scipy                    1.9.0
seaborn                  0.11.2
Send2Trash               1.8.0
sentry-sdk               1.15.0
serializable             0.2.1
session-info             1.0.0
setproctitle             1.3.2
shap                     0.41.0
simplejson               3.17.6
sklearn                  0.0
slicer                   0.0.7
smmap                    5.0.0
sniffio                  1.3.0
soupsieve                2.3.2.post1
stack-data               0.5.1
statsmodels              0.13.5
stdlib-list              0.8.0
swagger-spec-validator   2.7.4
tabulate                 0.9.0
tensorboard              2.9.1
tensorboard-data-server  0.6.1
tensorboard-plugin-wit   1.8.1
tensorflow-addons        0.17.1
tensorflow-datasets      4.7.0
tensorflow-estimator     2.9.0
tensorflow-macos         2.9.2
tensorflow-metadata      1.10.0
tensorflow-metal         0.5.1
termcolor                1.1.0
terminado                0.16.0
textwrap3                0.9.2
threadpoolctl            3.1.0
tinycss2                 1.2.1
tinytimer                0.0.0
toml                     0.10.2
tomli                    2.0.1
toolz                    0.12.0
tornado                  6.2
traitlets                5.5.0
twobitreader             3.1.7
typechecks               0.1.0
typeguard                2.13.3
typing_extensions        4.3.0
umap-learn               0.5.3
unicodedata2             14.0.0
uri-template             1.2.0
urllib3                  1.26.11
venn                     0.1.3
wandb                    0.13.10
wcwidth                  0.2.5
webcolors                1.12
webencodings             0.5.1
websocket-client         1.4.1
Werkzeug                 2.2.2
widgetsnbextension       4.0.3
wrapt                    1.14.1
xgboost                  1.6.2
xxhash                   3.2.0
yarl                     1.8.2

DiyuanLu avatar Mar 10 '23 08:03 DiyuanLu

I'm not sure what to tell you, the released version is not really relying on any non-standard packages other than numpy and matplotlib...

Phlya avatar Mar 10 '23 08:03 Phlya

You can try using the unreleased version from the master branch.

Phlya avatar Mar 10 '23 10:03 Phlya

This behavior is caused by the following:

%matplotlib inline -> works well %matplotlib notebook-> broken

Unfortunately, in many cases I need the notebook backend for interactivity and I can't temporarily switch the backend, because it disables all the interactivity in my existing plots. It would be great if it could be made to work with the notebook backend.

olavl avatar Apr 19 '23 17:04 olavl

I am also seeing this.

lericson avatar Apr 25 '23 06:04 lericson

It went away with current master.

lericson avatar Apr 25 '23 06:04 lericson

I am assuming it works with the current version... Feel free to reopen or clarify in the PR mentioned above.

Phlya avatar Mar 18 '24 16:03 Phlya