cphyc / matplotlib-label-lines

Label line using matplotlib.
MIT License
301 stars 28 forks source link

How can i add labels to the circles with radius size? #53

Closed syedhamidali closed 3 years ago

syedhamidali commented 3 years ago
t = np.linspace(0,2*np.pi)
A = [10,25]
fig = plt.figure(figsize=[5,5])
for r in [5,10,15,20,25]:
    plt.plot(r*np.cos(t),r*np.sin(t),lw=1, color='k',label=str(A))
    labelLines(plt.gca().get_lines(), zorder=3.5)
plt.draw()

download (29)

cphyc commented 3 years ago

Hi, I don't think I understand what the issue is, as if I amend your code as follows, each line is labelled by their radius

In [14]: t = np.linspace(0,2*np.pi)
    ...: A = [10,25]
    ...: fig = plt.figure(figsize=[5,5])
    ...: for r in [5,10,15,20,25]:
    ...:     l, = plt.plot(r*np.cos(t),r*np.sin(t),lw=1, color='k',label=f"${r=}$")
   ....:     #                                                          ^  note that the `label=` has been modified
    ...:     labelLine(l, 0, zorder=3.5)
    ...: plt.draw()

image The label that will be drawn on each line is the one provided in the label= keyword argument in the plt.plot call.

syedhamidali commented 3 years ago

Thank you dear.

On Wed, 18 Aug, 2021, 4:49 pm Corentin Cadiou, @.***> wrote:

Closed #53 https://github.com/cphyc/matplotlib-label-lines/issues/53.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cphyc/matplotlib-label-lines/issues/53#event-5174193007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AISCO3TYVMWQR5CBDGUHNNDT5OJN3ANCNFSM5CGBITXA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .