def plot_outline(label="Crack zone"): if outline: plt.gca().add_patch( mpl.patches.Rectangle( (c_x_start, c_z_start), c_x_end - c_x_start, c_z_end - c_z_start, fill=not scatter, edgecolor="black", facecolor="white", alpha=1, label=label, ))
def set_labels(ylabel: str, xlabel: str): for i, y, x in [ (1, True, False), (2, False, False), (3, True, False), (4, False, False), (5, True, True), (6, False, True), ]: plt.subplot(3, 2, i) ax = plt.gca() if y: plt.ylabel(ylabel) else: ax.axes.yaxis.set_ticklabels([]) if x: plt.xlabel(xlabel) ax.axes.xaxis.set_ticklabels([]) ymin, ymax = np.inf, -np.inf for i in range(1, 6 + 1): plt.subplot(3, 2, i) ymin = min(ymin, plt.ylim()[0]) ymax = max(ymax, plt.ylim()[1]) for i in range(1, 6 + 1): plt.subplot(3, 2, i) plt.ylim((ymin, ymax))
def plot_event( c: Config, event: Event, start_index: int, response_type: ResponseType, at: Point, overlap: Tuple[int, int], y_max: float, y_min: float, ): """Plot a single event with timing and overlap information.""" time_series = event.get_time_series(noise=False) time_series_with_noise = event.get_time_series(noise=True) x_min = start_index * c.time_step x_max = (start_index + len(time_series)) * c.time_step overlap_height = y_max - y_min # Plot LHS overlap. if overlap[0]: overlap_width = (x_max - x_min) * (overlap[0] / len(time_series)) plt.gca().add_patch( patches.Rectangle( xy=(x_min, y_min), width=overlap_width, height=overlap_height, alpha=0.1, )) # Plot RHS overlap. if overlap[1]: overlap_width = (x_max - x_min) * (overlap[1] / len(time_series)) plt.gca().add_patch( patches.Rectangle( xy=(x_max - overlap_width, y_min), width=overlap_width, height=overlap_height, alpha=0.1, )) print_i(f"x_min = {x_min}") print_i(f"x_max = {x_max}") print_i(f"x.shape = {np.linspace(x_min, x_max, len(time_series)).shape}") x_axis = np.linspace(x_min, x_max, num=len(time_series)) plt.plot(x_axis, time_series_with_noise, color="tab:orange") plt.plot(x_axis, time_series, color="tab:blue") plt.title(f"{response_type.name()} at {at.x:.2f}m") plt.xlabel("time (s)") plt.ylabel(f"{response_type.name().lower()} ({response_type.units()})")
def top_view_vehicles( bridge: Bridge, mv_vehicles: List[MvVehicle], time: float, all_vehicles: Optional[List[Vehicle]] = None, ): """Plot vehicles on a bridge in top view at a given time. Args: bridge: Bridge, bridge on which to draw the vehicles. mv_vehicles: List[MvVehicle], vehicles currently on the bridge. time: float, time at which to draw each vehicles. all_vehicles: Optional[List[Vehicle]], vehicles from which to derive color scale, if None default is 'mv_vehicles'. """ if all_vehicles is None: all_vehicles = mv_vehicles for mv_vehicle in mv_vehicles: # Left-most position of each vehicles axle. xl = min(mv_vehicle.xs_at(time=time, bridge=bridge)) # Center of the lane. z_center = bridge.lanes[mv_vehicle.lane].z_center # Bottom position on z-axis of vehicles. zb = z_center - (mv_vehicle.axle_width / 2) # Length, not allowed to extend beyond the bridge. length = mv_vehicle.length if xl + length <= bridge.x_min: continue if xl >= bridge.x_max: continue if xl < bridge.x_min: length -= abs(bridge.x_min - xl) xl = bridge.x_min if xl + length > bridge.x_max: length -= abs(xl + length - bridge.x_max) plt.gca().add_patch( patches.Rectangle( (xl, zb), length, mv_vehicle.axle_width, facecolor=mv_vehicle.color(all_vehicles), ))
def matrix_subplots( c: Config, resp_matrix: ResponsesMatrix, num_subplots: int, num_x: int, z_frac: float, rows: int = 4, save: str = None, plot_func=None, ): """For each subplot plot matrix fem using the given function.""" cols = int(num_subplots / rows) if cols != num_subplots / rows: print_w(f"Rows don't divide number of simulations, cols = {cols}" + f", sims = {num_subplots / rows}" + f", num_subplots = {num_subplots}, rows = {rows}") cols += 1 y_min, y_max = 0, 0 # Plot each IL and bridge deck side. for i, response_frac in enumerate(np.linspace(0, 1, rows * cols)): plt.subplot(rows, cols, i + 1) plot_bridge_deck_side(c.bridge, show=False, equal_axis=False) rs = plot_func(c, resp_matrix, i, response_frac, z_frac=z_frac, num_x=num_x) plt.axvline(x=c.bridge.x(x_frac=response_frac), color="red") # Keep track of min and max on y axis (only when non-zero fem). if any(rs): _y_min, _y_max = plt.gca().get_ylim() y_min, y_max = min(y_min, _y_min), max(y_max, _y_max) # Ensure y_min == -y_max. y_min = min(y_min, -y_max) y_max = max(-y_min, y_max) for i, _ in enumerate(np.linspace(0, 1, rows * cols)): plt.subplot(rows, cols, i + 1) plt.ylim(y_min, y_max) plt.tight_layout() if save: plt.savefig(save) plt.close()