from matplotlib import pyplot as plt from math import sin, cos, pi def createPend(length, radian): x = length * sin(radian) y = length * cos(radian) line = plt.Polygon(((0,0), (x,y)), closed=False, color="black") circle = plt.Circle((x,y), 0.1) return (line, circle,) pend = createPend(1, pi/4) fig = plt.gcf() ax = plt.axes(xlim=(-1.5,1.5), ylim=(1.5,-1.5)) ax.set_aspect("equal") for obj in pend: ax.add_patch(obj) plt.show()
―――――――――――――――――――――――――――――――
線分は matplotlib.lines.Line2D() のほうが簡単であった。
from matplotlib import pyplot as plt from matplotlib import lines as mlines from math import sin, cos, pi def createPend(length, radian): x = length * sin(radian) y = length * cos(radian) line = mlines.Line2D((0,x),(0,y)) circle = plt.Circle((x,y), 0.1) return {"line" : line, "circle" : circle} fig = plt.gcf() ax = plt.axes(xlim=(-1.5,1.5), ylim=(1.5,-1.5)) ax.set_aspect("equal") pend = createPend(1, pi/4) ax.add_line(pend["line"]) ax.add_patch(pend["circle"]) plt.show()