Ejemplo n.º 1
0
def plot(opt):
    """Main plotting function."""
    LOG.info(f"Starting plotting of tfs files: {list2str(opt.files):s}")
    if opt.output is not None:
        save_config(Path(opt.output), opt, __file__)

    # preparations
    opt = _check_opt(opt)
    pstyle.set_style(opt.plot_styles, opt.manual_style)

    # extract data
    fig_collection = sort_data(
        opt.get_subdict([
            'files', 'planes', 'x_columns', 'y_columns', 'error_columns',
            'file_labels', 'column_labels', 'x_labels', 'y_labels',
            'same_axes', 'same_figure', 'output', 'output_prefix',
            'share_xaxis'
        ]))

    # plotting
    _create_plots(
        fig_collection,
        opt.get_subdict([
            'x_lim', 'y_lim', 'ncol_legend', 'single_legend', 'change_marker',
            'errorbar_alpha', 'vertical_lines', 'show'
        ]))

    return fig_collection.fig_dict
Ejemplo n.º 2
0
def _set_plotstyle(manual_style):
    mstyle = MANUAL_STYLE_DEFAULT
    mstyle.update(manual_style)
    pstyle.set_style("standard", mstyle)
Ejemplo n.º 3
0
def _plot_bbq_data(bbq_df,
                   interval=None,
                   x_lim=None,
                   y_lim=None,
                   two_plots=False):
    """
    Plot BBQ data.

    Args:
        bbq_df: BBQ Dataframe with moving average columns.
        interval: start and end time of used interval, will be marked with red bars.
        x_lim: x limits (time).
        y_lim: y limits (tune).
        output: Path to the output file.
        show: Shows plot if ``True``.
        two_plots: Plots each tune in it's own axes if ``True``.

    Returns:
        Plotted figure.
    """
    LOG.debug("Plotting BBQ data.")

    pstyle.set_style(
        "standard", {
            u'figure.figsize': [12.24, 7.68],
            u"lines.marker": u"",
            u"lines.linestyle": u""
        })

    fig, axs = plt.subplots(1 + two_plots, 1)

    if not two_plots:
        axs = [axs, axs]

    handles = [None] * (3 * len(PLANES))
    for idx, plane in enumerate(PLANES):
        color = pcolors.get_mpl_color(idx)
        mask = np.array(bbq_df[get_used_in_mav_col(plane)], dtype=bool)

        # plot and save handles for nicer legend
        handles[idx] = axs[idx].plot(
            [i.datetime for i in bbq_df.index],
            bbq_df[get_bbq_col(plane)],
            color=pcolors.change_color_brightness(color, .4),
            marker="o",
            markerfacecolor="None",
            label="$Q_{:s}$".format(plane.lower(), ))[0]
        filtered_data = bbq_df.loc[mask, get_bbq_col(plane)].dropna()
        handles[len(PLANES) + idx] = axs[idx].plot(
            filtered_data.index,
            filtered_data.values,
            color=pcolors.change_color_brightness(color, .7),
            marker=".",
            label="filtered".format(plane.lower()))[0]
        handles[2 * len(PLANES) + idx] = axs[idx].plot(
            bbq_df.index,
            bbq_df[get_mav_col(plane)],
            color=color,
            linestyle="-",
            label="moving av.".format(plane.lower()))[0]

        if (y_lim is None or y_lim[0] is None) and two_plots:
            axs[idx].set_ylim(bottom=min(bbq_df.loc[mask, get_bbq_col(plane)]))

        if (y_lim is None or y_lim[1] is None) and two_plots:
            axs[idx].set_ylim(top=max(bbq_df.loc[mask, get_bbq_col(plane)]))

    # things to add/do only once if there is only one plot
    for idx in range(1 + two_plots):
        if interval:
            axs[idx].axvline(x=interval[0], color="red")
            axs[idx].axvline(x=interval[1], color="red")

        if two_plots:
            axs[idx].set_ylabel("$Q_{:s}$".format(PLANES[idx]))
        else:
            axs[idx].set_ylabel('Tune')

        if y_lim is not None:
            axs[idx].set_ylim(y_lim)
        axs[idx].yaxis.set_major_formatter(FormatStrFormatter('%.5f'))

        if x_lim is not None:
            axs[idx].set_xlim(x_lim)
        axs[idx].set_xlabel('Time')
        axs[idx].xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))

        if idx:
            # don't show labels on upper plot (if two plots)
            # use the visibility to allow cursor x-position to be shown
            axs[idx].tick_params(labelbottom=False)
            axs[idx].xaxis.get_label().set_visible(False)

        if not two_plots or idx:
            # reorder legend
            axs[idx].legend(
                handles,
                [h.get_label() for h in handles],
                loc='lower right',
                bbox_to_anchor=(1.0, 1.01),
                ncol=3,
            )

    fig.tight_layout()
    fig.tight_layout()
    return fig