Phlya / adjustText

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

Doesn't work, seems to push text to infinite of nan values? #117

Closed ryandikdan closed 3 years ago

ryandikdan commented 3 years ago

It seems that the adjustment isn't working at all for me. I just installed it recently. Here's some of the code I'm using

for pop in populations:
    values = dataframe_eigenvec[dataframe_eigenvec['labeled_subpop'] == pop].index
    int_vals = []
    for val in values:
        int_vals.append(val)
    pdembed = pd.DataFrame(embedding)
    pdpopembed = pdembed.iloc[int_vals]
    texts = []
    texts.append(plt.text(
        pdpopembed[0].median(),
        pdpopembed[1].median(), pop))
    plt.scatter(
        pdpopembed[0],
        pdpopembed[1],
        s = 10,
        c = color_map[pop],
        label = pop)

plt.gca().set_aspect('equal', 'datalim')
plt.title('UMAP projection of gnomAD', fontsize=12)
plt.legend(bbox_to_anchor=(1,1), loc="upper left", ncol = 5)

adjust_text(texts)

And when i run it the terminal gives a couple,

posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values

I'm not sure what's going wrong, there are no other errors, but if I remove the adjust_text function from this code, the visual is no different. Does this sound familiar? Any package info I can give you about what I'm using?

Phlya commented 3 years ago

Are any of your values nan or inf? Ideally, can you reproduce it with some values that you can share in a simple example?

ryandikdan commented 3 years ago

Nevermind, I had the list initialization in the for loop so I was wiping it every time \facepalm. It works great, thanks!

Phlya commented 3 years ago

Oh right! usually I notice when people post with this problem :) You are far from the first. Glad it works.