def __init__(self):
fig = plt.figure(figsize=(10,4))
a1_z = fig.add_subplot(1, 11, 1)
a1_xy = fig.add_subplot(1, 11, (2, 6))
a2_z = fig.add_subplot(1, 11, 7)
a2_xy = fig.add_subplot(1, 11, (8, 12))
plt.tight_layout()
fig.suptitle("3D Sensor and Xbox Controller Demo", fontsize=18)
plt.setp(a1_z.get_xticklabels(), visible=False)
plt.setp(a2_z.get_xticklabels(), visible=False)
a1_z.set_title('3D Sensor Z')
a2_z.set_title('Xbox L Z')
a1_xy.set_title('3D Sensor XY')
a2_xy.set_title('Xbox L XY')
# Joy 1 Z
a1_z.set_ylabel('z')
self.line_z1 = Line2D([], [], color='blue', linewidth=20)
a1_z.add_line(self.line_z1)
a1_z.set_xlim(-1, 1)
a1_z.set_ylim(-1, 1)
# Joy 1 XY
a1_xy.set_xlabel('x')
a1_xy.set_ylabel('y')
self.line_xy1 = Line2D([], [], color='green', linewidth=3)
a1_xy.add_line(self.line_xy1)
a1_xy.set_xlim(-1, 1)
a1_xy.set_ylim(-1, 1)
# Joy 2 Z
a2_z.set_ylabel('z')
self.line_z2 = Line2D([], [], color='blue', linewidth=20)
a2_z.add_line(self.line_z2)
a2_z.set_xlim(-1, 1)
a2_z.set_ylim(0, 1)
# Joy 2 XY
a2_xy.set_xlabel('x')
a2_xy.set_ylabel('y')
self.line_xy2 = Line2D([], [], color='green', linewidth=3)
a2_xy.add_line(self.line_xy2)
a2_xy.set_xlim(-1, 1)
a2_xy.set_ylim(-1, 1)
animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)
python类TimedAnimation()的实例源码
def __init__(self):
fig = plt.figure()
ax1 = fig.add_subplot(1, 6, (1, 2))
ax2 = fig.add_subplot(1, 6, (3, 4))
ax3 = fig.add_subplot(1, 6, 5)
self.t = np.linspace(0, 80, 400)
self.x = np.cos(2 * np.pi * self.t / 10.)
self.y = np.sin(2 * np.pi * self.t / 10.)
self.z = 10 * self.t
ax1.set_xlabel('x')
ax1.set_ylabel('y')
self.line1 = Line2D([], [], color='black')
self.line1a = Line2D([], [], color='red', linewidth=2)
self.line1e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax1.add_line(self.line1)
ax1.add_line(self.line1a)
ax1.add_line(self.line1e)
ax1.set_xlim(-1, 1)
ax1.set_ylim(-2, 2)
ax1.set_aspect('equal', 'datalim')
ax2.set_xlabel('y')
ax2.set_ylabel('z')
self.line2 = Line2D([], [], color='black')
self.line2a = Line2D([], [], color='red', linewidth=2)
self.line2e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax2.add_line(self.line2)
ax2.add_line(self.line2a)
ax2.add_line(self.line2e)
ax2.set_xlim(-1, 1)
ax2.set_ylim(0, 800)
ax3.set_xlabel('x')
ax3.set_ylabel('z')
self.line3 = Line2D([], [], color='black')
self.line3a = Line2D([], [], color='red', linewidth=2)
self.line3e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax3.add_line(self.line3)
ax3.add_line(self.line3a)
ax3.add_line(self.line3e)
ax3.set_xlim(-1, 1)
ax3.set_ylim(0, 800)
animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)