Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make arrow that loops in matplotlib?

what is the right way to draw an arrow that loops back to point to its origin in matplotlib? i tried:

plt.figure()
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.annotate("", xy=(0.6, 0.9),
             xycoords="figure fraction",
             xytext = (0.6, 0.8),
             textcoords="figure fraction",
             fontsize = 10, \
             color = "k",
             arrowprops=dict(edgecolor='black',
                             connectionstyle="angle,angleA=-180,angleB=45",
                             arrowstyle = '<|-',
                             facecolor="k",
                             linewidth=1,
                             shrinkA = 0,
                             shrinkB = 0))
plt.show()

this doesn't give the right result:

arrow

the connectionstyle arguments are hard to follow from this page (http://matplotlib.org/users/annotations_guide.html).

i'm looking for is something like this or this:

loopy arrow

update: the answer linked to does not show how do this with plt.annotate which has other features i want to use. the proposal to use $\circlearrowleft$ marker is not a real solution.

like image 309
mvd Avatar asked May 29 '16 16:05

mvd


People also ask

How do I add an arrow to a line in Matplotlib?

Plot x and y with color=red and linewidth = 1. Use arrow method to add an arrow to the axes. The first two values in the arguments are the coordinates of the arrow base and the next two values are for the length of the arrow along X and Y direction. To display the figure, use show() method.

How do I annotate an arrow in Matplotlib?

We can add arrows to an annotation in Matplotlib by passing the arrowprops argument to the ax. annotate(~) method.

What is Pyplot CLF ()?

The clf() function in pyplot module of matplotlib library is used to clear the current figure.


1 Answers

Try this:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_xlim(1,3) 
ax.set_ylim(1,3)
ax.plot([2.5],[2.5],marker=r'$\circlearrowleft$',ms=100)
plt.show()

enter image description here

like image 96
tfv Avatar answered Oct 05 '22 03:10

tfv