adjustText icon indicating copy to clipboard operation
adjustText copied to clipboard

The text is not aligning properly with the arrows

Open Flock1 opened this issue 5 years ago • 13 comments

Hi,

I am trying your library but the text is not aligning properly with the arrows. The code I have written is as follows:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)   #top and bottom left
texts = [plt.text(p1_0[i], p2_0[i], idx_0[i]) for i in range(len(p1_0))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='blue'))
ax.scatter(p1_0,p2_0,marker = 'o',label = "Bit flip X")

texts = [plt.text(p1_1[i], p2_1[i], idx_1[i]) for i in range(len(p1_1))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='yellow'))
ax.scatter(p1_1,p2_1,marker = 's', label = "Bit flip Y")

texts = [plt.text(p1_2[i], p2_2[i], idx_2[i]) for i in range(len(p1_2))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='green'))
ax.scatter(p1_2,p2_2,marker = 'd', label = "Hadamard X")

texts = [plt.text(p1_3[i], p2_3[i], idx_3[i]) for i in range(len(p1_3))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='red'))
ax.scatter(p1_3,p2_3,marker = 'x', label = "Hadamard Y")

texts = [plt.text(p1_4[i], p2_4[i], idx_4[i]) for i in range(len(p1_4))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='purple'))
ax.scatter(p1_4,p2_4,marker = '+', label = "measurement")

texts = [plt.text(p1_5[i], p2_5[i], idx_5[i]) for i in range(len(p1_5))]
adjust_text(texts,
            # only_move={'points':'', 'text':'y', 'objects':'y'}, force_text=0.75, force_objects=0.1,
            arrowprops=dict(arrowstyle='->', color='brown'))
ax.scatter(p1_5,p2_5,marker = '^', label = "nothing")

I end up getting an image like this arrows

Can you help me?

Flock1 avatar Dec 24 '19 14:12 Flock1

Hi, can you please make a minimal reproducible example?

Phlya avatar Dec 24 '19 15:12 Phlya

What do you mean?

Flock1 avatar Dec 24 '19 15:12 Flock1

Some code I can copy and run directly that shows the issue.

Sorry, I'm answering from my phone, maybe I'm missing something here.

Phlya avatar Dec 24 '19 15:12 Phlya

Oh, okay. That's fine. Answer when you have access to a machine. But please let me know what's the issue. Why is the text not aligning properly?

Flock1 avatar Dec 24 '19 15:12 Flock1

Some code I could run would help, here you don't include the actual values you used - and it can be much shorter.

Phlya avatar Dec 24 '19 16:12 Phlya

Here's are some values. You can assign the parameters these values and you'll get the graph:

https://gist.github.com/Flock1/2af3652a8cea1fb0f8ac69e2501538b0

Flock1 avatar Dec 25 '19 03:12 Flock1

I can't reproduce your issue. Using your values and your code I get this: image

Which versions of adjustText and matplotlib do you have?

Note that in general you should call adjust_text once per plot with all the texts, it won't repel objects used in different calls. And to avoid texts with the same coordinates from sticking together, you can add a tiny value to the coordinates, so that they start getting repelled.

Phlya avatar Dec 25 '19 09:12 Phlya

Hi

matplotlib: 2.2.3 adjusttext: 0.7.3.1

What do you suggest?

Flock1 avatar Dec 27 '19 06:12 Flock1

Can you try upgrading matplotlib?

On Fri, Dec 27, 2019, 08:22 Flock-Anizak [email protected] wrote:

Hi

matplotlib: 2.2.3 adjusttext: 0.7.3.1

What do you suggest?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Phlya/adjustText/issues/88?email_source=notifications&email_token=AAWCZOQHQT53DXOJULJ7PXDQ2WNKPA5CNFSM4J66WCL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHWU2UA#issuecomment-569199952, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWCZOVHMKT6CFQCGF5P2EDQ2WNKPANCNFSM4J66WCLQ .

Phlya avatar Dec 27 '19 06:12 Phlya

which version?

Flock1 avatar Dec 27 '19 14:12 Flock1

Something above 3 at least, can you just get the latest?

On Fri, Dec 27, 2019, 16:51 Flock-Anizak [email protected] wrote:

which version?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Phlya/adjustText/issues/88?email_source=notifications&email_token=AAWCZOXZTPVWCZ2JJZ2XMTDQ2YI77A5CNFSM4J66WCL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHXJRLA#issuecomment-569284780, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWCZOQN4QYTMHBALJAY2ZTQ2YI77ANCNFSM4J66WCLQ .

Phlya avatar Dec 27 '19 14:12 Phlya

I'll try that

Flock1 avatar Dec 27 '19 15:12 Flock1

I had the same problem, and it got better with autoalign=False

symphorien avatar Apr 17 '22 12:04 symphorien