def plot_coordinates(self, ts, qs, fig=None, ax=None, labels=None): fig, ax = default_fig(fig, ax) ax.set_title('Coordinates', fontsize=16) ax.set_xlabel('$\\theta_1$ (rad)', fontsize=16) ax.set_ylabel('$\\theta_2$ (rad)', fontsize=16) ax.plot(*qs.T, linewidth=3) return fig, ax
def plot_states(self, ts, xs, fig=None, ax=None, labels=None): fig, ax = default_fig(fig, ax) ax.set_title('States', fontsize=16) ax.set_xlabel('$\\theta$ (rad)', fontsize=16) ax.set_ylabel('$\\dot{\\theta}$ (rad / sec)', fontsize=16) ax.plot(*xs.T, linewidth=3) return fig, ax
def plot_tangents(self, ts, xs, fig=None, ax=None, skip=1): fig, ax = default_fig(fig, ax) ax.set_title('Tangent Vectors', fontsize=16) ax.set_xlabel('$\\theta_1$ (rad)', fontsize=16) ax.set_ylabel('$\\theta_2$ (rad)', fontsize=16) ax.plot(*xs[:, :2].T, linewidth=3) ax.quiver(*xs[::skip, :2].T, *xs[::skip, 2:].T, angles='xy') return fig, ax
def plot_states(self, ts, xs, fig=None, ax=None, labels=None): fig, ax = default_fig(fig, ax) ax.set_title('States', fontsize=16) ax.set_xlabel('$\\theta$ (rad)', fontsize=16) ax.set_ylabel('$\\dot{\\theta}$ (rad / sec)', fontsize=16) ax.plot(xs[:, 0], xs[:, 2], linewidth=3, label='$\\theta_1$') ax.plot(xs[:, 1], xs[:, 3], linewidth=3, label='$\\theta_2$') ax.legend(fontsize=16) return fig, ax
def plot_actions(self, ts, us, fig=None, ax=None, labels=None): fig, ax = default_fig(fig, ax) if labels is None: labels = ['$\\tau_1$ (N $\\cdot m$)', '$\\tau_2$ (N $\\cdot$ m)'] ax.set_title('Actions', fontsize=16) ax.set_xlabel(labels[0], fontsize=16) ax.set_ylabel(labels[1], fontsize=16) ax.plot(*us.T, linewidth=3) return fig, ax
def plot_physical(self, ts, xs, fig=None, ax=None, skip=1): fig, ax = default_fig(fig, ax) xs, zs, thetas = xs[:, :3].T dirs = array([sin(thetas), cos(thetas)])[:, ::skip] ax.set_title('Physical Space', fontsize=16) ax.set_xlabel('$x$ (m)', fontsize=16) ax.set_ylabel('$z$ (m)', fontsize=16) ax.quiver(xs[::skip], zs[::skip], *dirs, angles='xy') ax.plot(xs, zs, linewidth=3) ax.axis('equal') return fig, ax
def plot_physical(self, ts, xs, fig=None, ax=None, skip=1): fig, ax = default_fig(fig, ax) _, l, g = self.params thetas = xs[:, 0] rs = l * array([sin(thetas), cos(thetas)]) zs = 0 * thetas[::skip] ax.set_title('Physical space', fontsize=16) ax.set_xlabel('$x$ (m)', fontsize=16) ax.set_ylabel('$z$ (m)', fontsize=16) ax.plot([zs, rs[0, ::skip]], [zs, rs[1, ::skip]], 'k') ax.plot(*rs, linewidth=3) ax.axis('equal') return fig, ax
def plot_physical(self, ts, xs, fig=None, ax=None, skip=1): fig, ax = default_fig(fig, ax) _, _, l_1, l_2, _ = self.params theta_1s, theta_2s = xs[:, :2].T r_1s = l_1 * array([sin(theta_1s), cos(theta_1s)]) r_2s = r_1s + l_2 * array( [sin(theta_1s + theta_2s), cos(theta_1s + theta_2s)]) zs = 0 * theta_1s[::skip] ax.set_title('Physical space', fontsize=16) ax.set_xlabel('$x$ (m)', fontsize=16) ax.set_ylabel('$z$ (m)', fontsize=16) ax.plot([zs, r_1s[0, ::skip]], [zs, r_1s[1, ::skip]], 'k') ax.plot([r_1s[0, ::skip], r_2s[0, ::skip]], [r_1s[1, ::skip], r_2s[1, ::skip]], 'k') ax.plot(*r_1s, linewidth=3) ax.plot(*r_2s, linewidth=3) ax.axis('equal') return fig, ax