我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用matplotlib.pylab.suptitle()。
def plot_position(self, pos_true, pos_est): N = pos_est.shape[1] pos_true = pos_true[:, :N] pos_est = pos_est[:, :N] # Figure plt.figure() plt.suptitle("Position") # Ground truth plt.plot(pos_true[0, :], pos_true[1, :], color="red", marker="o", label="Grouth truth") # Estimated plt.plot(pos_est[0, :], pos_est[1, :], color="blue", marker="o", label="Estimated") # Plot labels and legends plt.xlabel("East (m)") plt.ylabel("North (m)") plt.axis("equal") plt.legend(loc=0)
def plot_position(self, pos_true, pos_est, cam_states): N = pos_est.shape[1] pos_true = pos_true[:, :N] pos_est = pos_est[:, :N] # Figure plt.figure() plt.suptitle("Position") # Ground truth plt.plot(pos_true[0, :], pos_true[1, :], color="red", label="Grouth truth") # color="red", marker="x", label="Grouth truth") # Estimated plt.plot(pos_est[0, :], pos_est[1, :], color="blue", label="Estimated") # color="blue", marker="o", label="Estimated") # Sliding window cam_pos = [] for cam_state in cam_states: cam_pos.append(cam_state.p_G) cam_pos = np.array(cam_pos).reshape((len(cam_pos), 3)).T plt.plot(cam_pos[0, :], cam_pos[1, :], color="green", label="Camera Poses") # color="green", marker="o", label="Camera Poses") # Plot labels and legends plt.xlabel("East (m)") plt.ylabel("North (m)") plt.axis("equal") plt.legend(loc=0)
def plot_velocity(self, timestamps, vel_true, vel_est): N = vel_est.shape[1] t = timestamps[:N] vel_true = vel_true[:, :N] vel_est = vel_est[:, :N] # Figure plt.figure() plt.suptitle("Velocity") # X axis plt.subplot(311) plt.plot(t, vel_true[0, :], color="red", label="Ground_truth") plt.plot(t, vel_est[0, :], color="blue", label="Estimate") plt.title("x-axis") plt.xlabel("Date Time") plt.ylabel("ms^-1") plt.legend(loc=0) # Y axis plt.subplot(312) plt.plot(t, vel_true[1, :], color="red", label="Ground_truth") plt.plot(t, vel_est[1, :], color="blue", label="Estimate") plt.title("y-axis") plt.xlabel("Date Time") plt.ylabel("ms^-1") plt.legend(loc=0) # Z axis plt.subplot(313) plt.plot(t, vel_true[2, :], color="red", label="Ground_truth") plt.plot(t, vel_est[2, :], color="blue", label="Estimate") plt.title("z-axis") plt.xlabel("Date Time") plt.ylabel("ms^-1") plt.legend(loc=0)
def plot_attitude(self, timestamps, att_true, att_est): # Setup N = att_est.shape[1] t = timestamps[:N] att_true = att_true[:, :N] att_est = att_est[:, :N] # Figure plt.figure() plt.suptitle("Attitude") # X axis plt.subplot(311) plt.plot(t, att_true[0, :], color="red", label="Ground_truth") plt.plot(t, att_est[0, :], color="blue", label="Estimate") plt.title("x-axis") plt.legend(loc=0) plt.xlabel("Date Time") plt.ylabel("rad s^-1") # Y axis plt.subplot(312) plt.plot(t, att_true[1, :], color="red", label="Ground_truth") plt.plot(t, att_est[1, :], color="blue", label="Estimate") plt.title("y-axis") plt.legend(loc=0) plt.xlabel("Date Time") plt.ylabel("rad s^-1") # Z axis plt.subplot(313) plt.plot(t, att_true[2, :], color="red", label="Ground_truth") plt.plot(t, att_est[2, :], color="blue", label="Estimate") plt.title("z-axis") plt.legend(loc=0) plt.xlabel("Date Time") plt.ylabel("rad s^-1")
def plot_accelerometer(self): """Plot accelerometer""" accel_x = [data["af"] for data in self.oxts] accel_y = [data["al"] for data in self.oxts] accel_z = [data["au"] for data in self.oxts] fig = plt.figure() ax1 = fig.add_subplot(311) ax2 = fig.add_subplot(312) ax3 = fig.add_subplot(313) ax1.plot(self.timestamps, accel_x) ax2.plot(self.timestamps, accel_y) ax3.plot(self.timestamps, accel_z) plt.suptitle("Accelerometer") ax1.set_xlabel("Date Time") ax1.set_ylabel("ms^-2") ax2.set_xlabel("Date Time") ax2.set_ylabel("ms^-2") ax2.set_xlabel("Date Time") ax3.set_ylabel("ms^-2") ax1.set_xlim([self.timestamps[0], self.timestamps[-1]]) ax2.set_xlim([self.timestamps[0], self.timestamps[-1]]) ax3.set_xlim([self.timestamps[0], self.timestamps[-1]]) fig.tight_layout()
def plot_gyroscope(self): """Plot gyroscope""" gyro_x = [data["wf"] for data in self.oxts] gyro_y = [data["wl"] for data in self.oxts] gyro_z = [data["wu"] for data in self.oxts] fig = plt.figure() plt.suptitle("Gyroscope") ax1 = fig.add_subplot(311) ax2 = fig.add_subplot(312) ax3 = fig.add_subplot(313) ax1.plot(self.timestamps, gyro_x) ax1.set_xlabel("Date Time") ax1.set_ylabel("rad s^-1") ax1.set_xlim([self.timestamps[0], self.timestamps[-1]]) ax2.plot(self.timestamps, gyro_y) ax2.set_xlabel("Date Time") ax2.set_ylabel("rad s^-1") ax2.set_xlim([self.timestamps[0], self.timestamps[-1]]) ax3.plot(self.timestamps, gyro_z) ax3.set_xlabel("Date Time") ax3.set_ylabel("rad s^-1") ax3.set_xlim([self.timestamps[0], self.timestamps[-1]]) fig.tight_layout()
def plot_ground_truth(self): """Plot ground truth""" # Home point lat_ref = self.oxts[0]['lat'] lon_ref = self.oxts[0]['lon'] alt_ref = self.oxts[0]['alt'] # Calculate position relative to home point ground_truth_x = [0.0] ground_truth_y = [0.0] ground_truth_z = [0.0] for i in range(1, len(self.oxts)): lat = self.oxts[i]['lat'] lon = self.oxts[i]['lon'] alt = self.oxts[i]['alt'] dist_N, dist_E = latlon_diff(lat_ref, lon_ref, lat, lon) height = alt - alt_ref ground_truth_x.append(dist_E) ground_truth_y.append(dist_N) ground_truth_z.append(height) # Plot fig = plt.figure() plt.suptitle("Ground Truth") ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) ax1.plot(ground_truth_x, ground_truth_y) ax1.axis('equal') ax1.set_xlabel("East (m)") ax1.set_ylabel("North (m)") ax2.plot(self.timestamps, ground_truth_z) ax2.set_xlabel("Date Time") ax2.set_ylabel("Height (m)") fig.tight_layout()
def plot_projections(points): num_images = len(points) plt.figure() plt.suptitle('3D to 2D Projections', fontsize=16) for i in range(num_images): plt.subplot(1, num_images, i+1) ax = plt.gca() ax.set_aspect('equal') ax.plot(points[i][0], points[i][1], 'r.')
def plot_cube(points3d, title=''): fig = plt.figure() fig.suptitle(title, fontsize=16) ax = fig.gca(projection='3d') ax.set_aspect('equal') ax.plot(points3d[0], points3d[1], points3d[2], 'b.') ax.set_xlabel('x axis') ax.set_ylabel('y axis') ax.set_zlabel('z axis') ax.view_init(elev=135, azim=90) return ax
def plot_colat_slice(self, component, colat, valmin, valmax, iteration=0, verbose=True): #- Some initialisations. ------------------------------------------------------------------ colat = np.pi * colat / 180.0 n_procs = self.setup["procs"]["px"] * self.setup["procs"]["py"] * self.setup["procs"]["pz"] vmax = float("-inf") vmin = float("inf") fig, ax = plt.subplots() #- Loop over processor boxes and check if colat falls within the volume. ------------------ for p in range(n_procs): if (colat >= self.theta[p,:].min()) & (colat <= self.theta[p,:].max()): #- Read this field and make lats & lons. ------------------------------------------ field = self.read_single_box(component,p,iteration) r, lon = np.meshgrid(self.z[p,:], self.phi[p,:]) x = r * np.cos(lon) y = r * np.sin(lon) #- Find the colat index and plot for this one box. -------------------------------- idx=min(np.where(min(np.abs(self.theta[p,:]-colat))==np.abs(self.theta[p,:]-colat))[0]) colat_effective = self.theta[p,idx]*180.0/np.pi #- Find min and max values. ------------------------------------------------------- vmax = max(vmax, field[idx,:,:].max()) vmin = min(vmin, field[idx,:,:].min()) #- Make a nice colourmap and plot. ------------------------------------------------ my_colormap=cm.make_colormap({0.0:[0.1,0.0,0.0], 0.2:[0.8,0.0,0.0], 0.3:[1.0,0.7,0.0],0.48:[0.92,0.92,0.92], 0.5:[0.92,0.92,0.92], 0.52:[0.92,0.92,0.92], 0.7:[0.0,0.6,0.7], 0.8:[0.0,0.0,0.8], 1.0:[0.0,0.0,0.1]}) cax = ax.pcolor(x, y, field[idx,:,:], cmap=my_colormap, vmin=valmin,vmax=valmax) #- Add colobar and title. ------------------------------------------------------------------ cbar = fig.colorbar(cax) if component in UNIT_DICT: cb.set_label(UNIT_DICT[component], fontsize="x-large", rotation=0) plt.suptitle("Vertical slice of %s at %i degree colatitude" % (component, colat_effective), size="large") plt.axis('equal') plt.show() #============================================================================================== #- Plot depth slice. #==============================================================================================