I think you need to do the maths on your points yourself and then annotate the points on the plot using annotate()
. It's hard to tell from your example whether val
and ar
are single values or vectors - I think single values given the syntax you're using. Here's an example with a function to do the maths and an example use of annotate
- I've tried to keep the plotting bits the same as your code and just add the bits to calculate degrees and then put them on the axes
import math
import matplotlib.pyplot as plt
#This function does the maths - turns co-ordinates into angles
#with 0 on +ve x axis, increasing anti-clockwise
def get_theta(x,y):
theta = math.atan(y*1.0/x) / (2*math.pi) * 360
if x < 0:
theta += 180
if theta < 0:
theta += 360
return theta
def visualize(val,ar):
ax = plt.gca()
ax.plot([val-5],[ar-5], marker='o', color='r')
ax.set_xlim([-5,5])
ax.set_ylim([-5,5])
#insert the following to calculate the angles and
#then annotate them on the plot
x,y = val-5,ar-5
label = get_theta(x, y)
ax.annotate(str(label)+' degrees', xy = (x, y), xytext = (-20, 20),textcoords = 'offset points')
if __name__ == '__main__':
plt.figure()
x = [6,4,4,6]
y = [6,6,4,4]
for (val, ar) in zip(x,y):
visualize(val,ar)
plt.draw()
plt.grid()
plt.show()
Further variations on what you can do with annotations are in the docs.
Output
