Hi all,
this is basically still using Julia (calling Python), but I want to know whether this code works:
using PyCall
py"""
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
from matplotlib.lines import Line2D
import math
sim_score =[0.993832,0.543218,0.234745 ,0.873513,0.234565,0.789212]
def get_angle_text(angle_plot):
angle = angle_plot.get_label()[:-1] # Excluding the degree symbol
angle = "%0.2f" % float(angle) + u"\u00b0" # Display angle upto 2 decimal places
# Set the label position
x_width = angle_plot.width / 2
y_width = math.sin(math.radians(angle_plot.theta2))
return [x_width, y_width, angle]
def get_angle_plot(line1, offset=1, color=None, origin=[0, 0], len_x_axis=1, len_y_axis=1):
l1xy = line1.get_xydata()
# Angle between line1 and x-axis
slope = (l1xy[1][1] - l1xy[0][1]) / float(l1xy[1][0] - l1xy[0][0])
angle = abs(math.degrees(math.atan(slope))) # Taking only the positive angle
if color is None:
color = line1.get_color() # Uses the color of line 1 if color parameter is not passed.
return Arc(origin, len_x_axis * offset, len_y_axis * offset, 0, 0, angle, color=color,
label=str(angle) + u"\u00b0")
sim_score = [0.993832, 0.543218, 0.234745, 0.873513]
fig = plt.figure()
ax = fig.add_subplot(111)
offset = 0
for i in sim_score:
offset += 2 # you play with this value to draw arc spaced from the previous
a = math.acos(i)
b = a * 180 / math.pi
point = (0, 0)
x, y = point
length = 10
# find the end point
endy = length * math.sin(math.radians(b))
endx = length * math.cos(math.radians(b))
line = Line2D([x, endx], [y, endy], linewidth=1, linestyle="-", color="blue")
angle_plot = get_angle_plot(line, offset)
angle_text = get_angle_text(angle_plot)
ax.add_line(line )
ax.add_patch(angle_plot)
ax.text(*angle_text) # To display the angle value
ax.set_ylim([0, 10])
ax.set_xlim([0, 10])
plt.show()
"""
I retrieve errors of:
/home/browni/.julia/packages/PyCall/7a7w0/src/pyeval.jl:57: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
** depbuf = IOBuffer()**
I have been reading from these two sources of StackOverFlow:
I have been searching and there is no Julia code to plot angle directly between two intersecting vectors/lines, correct me if I am wrong. I tried before when create a unit circle but it needs manual adjustment and not easy at all to be applied here.