Phlya / adjustText

A small library for automatically adjustment of text position in matplotlib plots to minimize overlaps.
https://adjusttext.readthedocs.io/
MIT License
1.5k stars 87 forks source link

Altering Data #159

Closed ekwan closed 10 months ago

ekwan commented 1 year ago

Does adjustText change the backing data for the graph? If those data are provided as a DataFrame, you can get a SettingWithCopyWarning.

Phlya commented 1 year ago

Good question, I never tested or checked this purposefully. I wouldn't have expected it to modify the data, but the warning is worrying. I will check at some point... For now just in case you want to be sure, provide the x and y coordinates as copies, I guess.

ekwan commented 10 months ago
/Users/kwaneu/sw/miniconda/miniconda3/envs/python/lib/python3.11/site-packages/adjustText/__init__.py:377: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
  xp, yp = x[j], y[j]

I have adjustText 0.8 and this was triggered by:

adjust_text(texts, x = df.C, y = df.H)

I can certainly get around this by making copies, but it does look like the underlying df is altered, and with the DeprecationWarning, this behavior doesn't seem optimal.

Phlya commented 10 months ago

I just tried it with the latest version from github and didn't get a warning and the data are not altered... So perhaps this is fixed now. Feel free to reopen if you can get reproduce this issue with the master version!