Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing obtuse circular arc with arrowhead in matplotlib

I am new to Python, though I do have previous programming experience. My current interest is to generate good quality schematics (and maybe later on also data graphs).

I need to draw a circlar arc with an arrowhead at the end point. I have sieved through many posts and tried my hand at a few examples, but it seems I still miss some basic knowledge. So I need something like this:

http://i.stack.imgur.com/Z5V86.png

I was experimenting with the example below, trying to initially plot a circular arc, but even this does not work. I am using matplotlib.patches but I am open to other suggestions for what I need.

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Arc
from matplotlib import cm, colors, patches
from math import pi

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ellipse = Arc([2.5,2.5],1,1,0,0,pi,color='green', linewidth='0.5')
ax.add_patch(ellipse)
plt.show()
like image 863
malteser Avatar asked Dec 17 '13 12:12

malteser


1 Answers

Well,

  • if you want an angle of pi, pass 180.
  • linewidth must be a scalar. pass .5 and not '.5' as linewidth parameter
  • you need to change the limits of the axes, or you won't see the arc. Add something like ax.set_xlim(1.5,3.1) and ax.set_ylim(2.4,3.7).

You may also want to opt for another strategy, something like

ax.plot([.5],[.5],marker=r'$\circlearrowleft$',ms=100)

like image 115
gg349 Avatar answered Oct 25 '22 09:10

gg349