Пример #1
0
 def plot_subplots(
         self, fig_num: int, title: str, raw: np.ndarray,
         smoothed: np.ndarray,
         axes_lbl_entries: Sequence[str]) -> matplotlib.figure.Figure:
     """Plot position or orientation into 3 separate subplots for each spatial dimension."""
     fig = plt.figure(fig_num)
     axs = fig.subplots(3, 1, sharex=True)
     raw_lines = marker_graph_init(axs,
                                   raw,
                                   '',
                                   self.frame_nums,
                                   color='red')
     for idx, ax in enumerate(axs):
         plot_utils.update_ylabel(ax, axes_lbl_entries[idx], font_size=10)
     smoothed_lines = marker_graph_add(axs,
                                       smoothed,
                                       self.frame_nums,
                                       color='green')
     plt.tight_layout()
     plt.subplots_adjust(top=0.94)
     fig.suptitle(title)
     fig.legend((raw_lines[0], smoothed_lines[0]), ('Raw', 'Smoothed'),
                ncol=2,
                handlelength=0.75,
                handletextpad=0.25,
                columnspacing=0.5,
                loc='lower left')
     make_interactive()
     return fig
def marker_diff_his_init(ax: np.ndarray, filtered_diff: np.ndarray, x_label: str, color: str) \
        -> List[matplotlib.patches.Polygon]:
    """Histogram plot each column of filtered_diff ((n,3) numpy array) onto the axes provided in ax.

    Additionally, visually format each Axes and include a x_label on 2nd Axes.
    """

    polygons_filtered = []
    for n in range(3):
        current_filtered_diff = filtered_diff[:, n]
        _, _, patches_filtered = ax[n].hist(
            current_filtered_diff[~np.isnan(current_filtered_diff)],
            bins=20,
            histtype='step',
            color=color)
        polygons_filtered.append(patches_filtered[0])
        plot_utils.update_spines(ax[n])
        plot_utils.update_xticks(ax[n], font_size=8)
        plot_utils.update_yticks(ax[n], fontsize=8)

        if n == 1:
            plot_utils.update_xlabel(ax[n], x_label, font_size=10)
        elif n == 0:
            plot_utils.update_ylabel(ax[n], 'Instances', font_size=10)

    return polygons_filtered
def create_summary_boxplot(ax: matplotlib.axes.Axes, diff_data: np.ndarray, y_label: str, group_names: List[str],
                           metric_names: List[str], n_obs_pos: Tuple[float, float]) \
                            -> Dict[str, List[matplotlib.lines.Line2D]]:
    num_metrics = len(metric_names)
    # calculations
    num_bars, num_obs, num_groups, box_positions = bp_utils.calc_bar_positions(diff_data, num_metrics)

    # create figure and rudimentary boxplot
    bp = bp_utils.create_rudimentary_bp(ax, diff_data, box_positions)

    # colormap
    color_map = plt.get_cmap('Dark2')

    # now start updating boxplot elements
    bp_utils.update_bp_boxes(bp, num_metrics, color_map)
    bp_utils.update_bp_whiskers(bp, num_metrics, color_map)
    bp_utils.update_bp_caps(bp, num_metrics, color_map)
    bp_utils.update_bp_medians(bp)
    bp_utils.update_bp_fliers(bp, num_metrics, color_map)
    bp_utils.bp_vertical_sep(ax, num_groups, num_metrics)
    bp_utils.update_bp_xticks_groups(ax, num_bars, num_groups, num_metrics, group_names, font_size=12)
    plot_utils.update_yticks(ax, fontsize=10)
    plot_utils.update_spines(ax)
    plot_utils.update_ylabel(ax, y_label, font_size=12)

    # add the number of observations
    props = dict(boxstyle='round', facecolor='none')
    ax.text(n_obs_pos[0], n_obs_pos[1], 'n=' + str(num_obs), transform=ax.transAxes, fontsize=12,
            verticalalignment='top', bbox=props)

    return bp
Пример #4
0
def marker_diff_graph(ax: matplotlib.axes.Axes, marker_data: np.ndarray,
                      y_label: str, x_label: Union[str, None],
                      x_data: np.ndarray, **kwargs) -> matplotlib.lines.Line2D:
    """Plot marker_data onto the axes provided in ax.

    Additionally, visually format the axes and include a y_label. **kwargs passed to matplotlib plot().
    """
    lines = ax.plot(x_data, marker_data, **kwargs)
    plot_utils.update_spines(ax)
    plot_utils.update_xticks(ax, font_size=8)
    plot_utils.update_yticks(ax, fontsize=8)
    if x_label:
        plot_utils.update_xlabel(ax, x_label, font_size=10)
    plot_utils.update_ylabel(ax, y_label, font_size=10)
    return lines
Пример #5
0
 def plot_kine_var(self, fig_num: int, title: str, y_labels: Sequence[str],
                   prev_filled: np.ndarray, smoothed: np.ndarray,
                   filled: np.ndarray,
                   sfs: np.ndarray) -> matplotlib.figure.Figure:
     """Plot torso position or orientation on one axes with different colors for each spatial dimension."""
     fig = plt.figure(fig_num)
     ax = fig.subplots(3, 1)
     prev_filled_lines = marker_graph_init(ax,
                                           prev_filled,
                                           '',
                                           self.frame_nums,
                                           color='red')
     smoothed_lines = marker_graph_add(ax,
                                       smoothed,
                                       self.frame_nums,
                                       color='blue')
     smoothed_filled_lines = marker_graph_add(ax,
                                              filled,
                                              self.frame_nums,
                                              ls=':',
                                              lw=2,
                                              color='green')
     sfs_lines = marker_graph_add(ax, sfs, self.frame_nums, color='green')
     for idx, sub_ax in enumerate(ax):
         plot_utils.update_ylabel(sub_ax, y_labels[idx], font_size=10)
         sub_ax.axvline(self.vicon_endpts[0])
         sub_ax.axvline(self.vicon_endpts[1])
         sub_ax.set_xlim(left=1)
     plt.tight_layout()
     fig.suptitle(title)
     fig.legend((prev_filled_lines[0], smoothed_lines[0],
                 smoothed_filled_lines[0], sfs_lines[0]),
                ('Prev Filled', 'Smoothed', 'Smoothed/Filled', 'SFS'),
                ncol=4,
                handlelength=0.75,
                handletextpad=0.25,
                columnspacing=0.5,
                loc='lower left')
     make_interactive()
     return fig
def kine_graph_init(ax: matplotlib.axes.Axes, marker_data: np.ndarray, y_label: str, x_data: np.ndarray,
                    plot_args=None) -> List[matplotlib.lines.Line2D]:
    """Plot each column of marker_data ((n,3) numpy array) onto the axes provided in ax.

    Additionally, visually format each Axes and include a y_label on 2nd Axes. **kwargs passed to matplotlib plot().
    """
    if plot_args is None:
        plot_args = [{}] * marker_data.shape[1]

    lines = []
    for dim in range(marker_data.shape[1]):
        current_line, = ax.plot(x_data, marker_data[:, dim], **plot_args[dim])
        lines.append(current_line)

    plot_utils.update_spines(ax)
    plot_utils.update_xticks(ax, font_size=8)
    plot_utils.update_yticks(ax, fontsize=8)
    ax.margins(x=0, y=0.05)
    ax.yaxis.set_major_locator(ticker.MaxNLocator(nbins=4, integer=True))
    plot_utils.update_xlabel(ax, 'Frame Number', font_size=10)
    plot_utils.update_ylabel(ax, y_label, font_size=10)

    return lines
def marker_graph_init(ax: np.ndarray, marker_data: np.ndarray, y_label: str, x_data: np.ndarray, **kwargs) \
        -> List[matplotlib.lines.Line2D]:
    """Plot each column of marker_data ((n,3) numpy array) onto the axes provided in ax.

    Additionally, visually format each Axes and include a y_label on 2nd Axes. **kwargs passed to matplotlib plot().
    """

    lines = []
    for n in range(3):
        current_line, = ax[n].plot(x_data, marker_data[:, n], **kwargs)
        lines.append(current_line)
        plot_utils.update_spines(ax[n])
        plot_utils.update_xticks(ax[n], font_size=8)
        plot_utils.update_yticks(ax[n], fontsize=8)
        ax[n].margins(x=0, y=0.05)
        ax[n].yaxis.set_major_locator(ticker.MaxNLocator(nbins=4,
                                                         integer=True))

        if n == 2:
            plot_utils.update_xlabel(ax[n], 'Frame Number', font_size=10)
        elif n == 1:
            plot_utils.update_ylabel(ax[n], y_label, font_size=10)
    return lines
def cov_trend_graph_init(ax: np.ndarray, variance_data: Any,
                         x_data: np.ndarray, y_labels: Sequence[str],
                         process_func: Callable,
                         **kwargs) -> List[List[matplotlib.lines.Line2D]]:
    """Plot each kinematic variable/dimension combination contained in variance_data (tuple of 3 kinematic variables,
    each comprised of a (n, 3) numpy array) onto the 3 rows (kinematic variable) and 3 columns (dimension) contained in
    ax.

    Apply process_func to each kinematic variable/dimension before plotting. Additionally, visually format each axes
    and include a y_label for the first column of each row. **kwargs passed to matplotlib plot().
    """

    lines = []
    # iterate over kinematic variable
    for i in range(3):
        # iterate over dimension
        dim_lines = []
        for j in range(3):
            line, = ax[i, j].plot(x_data, process_func(variance_data[i][:, j]),
                                  **kwargs)
            dim_lines.append(line)
            plot_utils.update_spines(ax[i, j])
            plot_utils.update_xticks(ax[i, j], font_size=8)
            plot_utils.update_yticks(ax[i, j], fontsize=8)
            ax[i, j].margins(x=0, y=0.05)
            ax[i, j].yaxis.set_major_locator(
                ticker.MaxNLocator(nbins=4, integer=True))

            if i == 2 and j == 1:
                plot_utils.update_xlabel(ax[i, j],
                                         'Frame Number',
                                         font_size=10)

            if j == 0:
                plot_utils.update_ylabel(ax[i, j], y_labels[i], font_size=10)
        lines.append(dim_lines)
    return lines