jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def plot_arbitrageur_portfolio_values(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    sns.lineplot(x=df.index, y='arbitrageur_portfolio_value', data=df, label='Arbitrageur Portfolio Value', ax=ax, linewidth=2)
    customize_plot(ax, 'Arbitrageur Portfolio Values Over Time', 'Index', 'Value in WAD')
//  [python]
def plot_lp_fees(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    sns.lineplot(x=df.index, y='accumulated_lp_fees_x', data=df, label='Accumulated LP Fees X', ax=ax, linewidth=2)
    sns.lineplot(x=df.index, y='accumulated_lp_fees_y', data=df, label='Accumulated LP Fees Y', ax=ax, linewidth=2)
    customize_plot(ax, 'Accumulated LP Fees Over Time', 'Index', 'Fees in WAD')
//  [python]
plt.figure(dpi=100, figsize=[18, 6])
ax = plt.subplot(1,2,1)
sns.tsplot(data=pd_data, time="steps", value="reward", unit="type", ax=ax)
//  [python]
plt.figure(dpi=100, figsize=[18, 6])
ax = plt.subplot(1,2,1)
sns.lineplot(data=pd_data, x="steps", y="reward", hue="type", ax=ax)
//  [python]
def plot_invariant(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    sns.lineplot(x=df.index, y=df['invariant'], data=df, label='Invariant', ax=ax, linewidth=2)
    customize_plot(ax, 'Invariant Over Time', 'Index', 'Invariant Y')
//  [python]
df['最低气温'] = df['最低气温'].str.replace('℃', '').astype(int)
df['最高气温'] = df['最高气温'].str.replace('℃', '').astype(int)
# 使用 seaborn 设置美观的图表样式
sns.set_style('whitegrid',{'font.sans-serif':['simhei','Arial']})
# 设置画布
plt.figure(figsize=(12, 6))
# 使用 seaborn 绘制线图
sns.pointplot(x=df['日期'], y=df['最高气温'], label='最高气温', color='crimson')
//  [python]
df['最低气温'] = df['最低气温'].str.replace('℃', '').astype(int)
df['最高气温'] = df['最高气温'].str.replace('℃', '').astype(int)
# 使用 seaborn 设置美观的图表样式
sns.set_style('whitegrid',{'font.sans-serif':['simhei','Arial']})
# 设置画布
plt.figure(figsize=(12, 6))
# 使用 seaborn 绘制线图
sns.lineplot(x=df['日期'], y=df['最高气温'], label='最高气温', color='crimson')
//  [python]
def plot_liquid_exchange_relative_reserves(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    sns.lineplot(x=df.index, y='liquid_exchange_relative_reserves_x', data=df, label='Relative Liquid Exchange Reserves X', ax=ax, linewidth=2)
    sns.lineplot(x=df.index, y='liquid_exchange_relative_reserves_y', data=df, label='Relative Liquid Exchange Reserves Y', ax=ax, linewidth=2)
    customize_plot(ax, 'Liquid Exchange Reserves Over Time', 'Index', 'Reserve in WAD')
//  [python]
def plot_portfolio_balances_and_values(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    # Plot the balances
    s.lineplot(x=df.index, y='portfolio_reserves_x', data=df, label='Portfolio Reserves X', ax=ax, linewidth=2, alpha=0.5, legend=False)
    s.lineplot(x=df.index, y='portfolio_reserves_y', data=df, label='Portfolio Reserves Y', ax=ax, linewidth=2, alpha=0.5, legend=False)

    # Create a second y-axis to plot the portfolio value
    ax2 = ax.twinx()
    s.lineplot(x=df.index, y='lp_portfolio_value', data=df, label='LP Portfolio Value', ax=ax2, linewidth=2, color='purple', legend=False)

    # Customize the plot
    ax.set_title('Portfolio Balances and LP Portfolio Values Over Time', fontsize=16)
    ax.set_xlabel('Index', fontsize=14)
    ax.set_ylabel('Balance in WAD', fontsize=14)
    ax.grid(True)

    ax2.set_ylabel('Portfolio Value in WAD', fontsize=14)

    # Combine legends from both axes
    lines, labels = ax.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(lines + lines2, labels + labels2, loc=0, fontsize=12)
//  [python]
def plot_portfolio_balances_and_values(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    # Plot the balances
    sns.lineplot(x=df.index, y='portfolio_reserves_x', data=df, label='Portfolio Reserves X', ax=ax, linewidth=2, alpha=0.5, legend=False)
    sns.lineplot(x=df.index, y='portfolio_reserves_y', data=df, label='Portfolio Reserves Y', ax=ax, linewidth=2, alpha=0.5, legend=False)

    # Create a second y-axis to plot the portfolio value
    ax2 = ax.twinx()
    sns.lineplot(x=df.index, y='lp_portfolio_value', data=df, label='LP Portfolio Value', ax=ax2, linewidth=2, color='purple', legend=False)

    # Customize the plot
    ax.set_title('Portfolio Balances and LP Portfolio Values Over Time', fontsize=16)
    ax.set_xlabel('Index', fontsize=14)
    ax.set_ylabel('Balance in WAD', fontsize=14)
    ax.grid(True)

    ax2.set_ylabel('Portfolio Value in WAD', fontsize=14)

    # Combine legends from both axes
    lines, labels = ax.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(lines + lines2, labels + labels2, loc=0, fontsize=12)
//  [python]
def plot_arbitrageur_balances_and_values(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    # Plot the balances
    sns.tsplot(time=df.index, value='arbitrageur_relative_balances_x', data=df, label='Relative Arbitrageur Balances X', ax=ax, linewidth=2, alpha=0.5, legend=False)
    sns.tsplot(time=df.index, value='arbitrageur_relative_balances_y', data=df, label='Relative Arbitrageur Balances Y', ax=ax, linewidth=2, alpha=0.5, legend=False)

    # Create a second y-axis to plot the portfolio value
    ax2 = ax.twinx()
    sns.tsplot(time=df.index, value='arbitrageur_portfolio_value', data=df, label='Arbitrageur Portfolio Value', ax=ax2, linewidth=2, color='purple', legend=False)

    # Customize the plot
    ax.set_title('Arbitrageur Balances and Portfolio Values Over Time', fontsize=16)
    ax.set_xlabel('Index', fontsize=14)
    ax.set_ylabel('Balance in WAD', fontsize=14)
    ax.grid(True)

    ax2.set_ylabel('Portfolio Value in WAD', fontsize=14)

    # Combine legends from both axes
    lines, labels = ax.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(lines + lines2, labels + labels2, loc=0, fontsize=12)
//  [python]
def plot_arbitrageur_balances_and_values(ax, df, start_index=None, end_index=None):
    if start_index is not None and end_index is not None:
        df = df[start_index:end_index]
    # Plot the balances
    sns.lineplot(x=df.index, y='arbitrageur_relative_balances_x', data=df, label='Relative Arbitrageur Balances X', ax=ax, linewidth=2, alpha=0.5, legend=False)
    sns.lineplot(x=df.index, y='arbitrageur_relative_balances_y', data=df, label='Relative Arbitrageur Balances Y', ax=ax, linewidth=2, alpha=0.5, legend=False)

    # Create a second y-axis to plot the portfolio value
    ax2 = ax.twinx()
    sns.lineplot(x=df.index, y='arbitrageur_portfolio_value', data=df, label='Arbitrageur Portfolio Value', ax=ax2, linewidth=2, color='purple', legend=False)

    # Customize the plot
    ax.set_title('Arbitrageur Balances and Portfolio Values Over Time', fontsize=16)
    ax.set_xlabel('Index', fontsize=14)
    ax.set_ylabel('Balance in WAD', fontsize=14)
    ax.grid(True)

    ax2.set_ylabel('Portfolio Value in WAD', fontsize=14)

    # Combine legends from both axes
    lines, labels = ax.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(lines + lines2, labels + labels2, loc=0, fontsize=12)
//  [python]
def plot_data(data, smooth_weight, foi, ax=None):
    valid_idxs = data[foi].notnull()
    x = list(data['global_step'][valid_idxs])
    y = data[foi][valid_idxs]
    y = smooth(list(y), args.smooth_weight)
    sns.tsplot(x=x, y=y, ax=ax)
//  [python]
def plot_data(data, smooth_weight, foi, ax=None):
    valid_idxs = data[foi].notnull()
    x = list(data['global_step'][valid_idxs])
    y = data[foi][valid_idxs]
    y = smooth(list(y), args.smooth_weight)
    sns.lineplot(x=x, y=y, ax=ax)
//  [python]
def plot_line(x, y, plot_type: str, plot_id: str, data=None, fig=None, **kwargs):
    # plot data lines based on plot type
    if plot_type == "plotly":
        fig.add_trace(go.Scatter(x=x, y=y, name=plot_id, **kwargs))
    else:
        sns.plt.plot(data, x, y, label=plot_id, **kwargs)
//  [python]
def plot_line(x, y, plot_type: str, plot_id: str, data=None, fig=None, **kwargs):
    # plot data lines based on plot type
    if plot_type == "plotly":
        fig.add_trace(go.Scatter(x=x, y=y, name=plot_id, **kwargs))
    else:
        sns.lineplot(data=data, x=x, y=y, label=plot_id, **kwargs)
//  [python]
dfs = []
for api, path in zip(snakemake.input.keys(), snakemake.input):
    df = pd.read_csv(path, skiprows=1, header=None, sep=" ")

    df.columns = ["API", "Memory", "Time"]
    df.API = api
    df.Time -= df.Time[0]
    dfs.append(df)

df = pd.concat(dfs, ignore_index=True)

fig, ax = plt.subplots(figsize=(8, 6))
sns.lineplot(data=df, y="Memory", x="Time", hue="API", style="API", ax=ax)
//  [python]
plt.xkcd()

df = pd.read_csv("pypi_downloads.csv")
# print(df.head())

ax = sns.pointplot(
    # x=df.project,
    y=df.cumulative_downloads,
    x=df.index,
    data=df,
    # palette="tab10",
    linewidth=2,
    # marker="o",
    color="#2d73b9",
)
//  [python]
plt.xkcd()

df = pd.read_csv("pypi_downloads.csv")
# print(df.head())

ax = sns.lineplot(
    # x=df.project,
    y=df.cumulative_downloads,
    x=df.index,
    data=df,
    # palette="tab10",
    linewidth=2,
    # marker="o",
    color="#2d73b9",
)
//  [python]
def plot(self, output_directory, *args, **kwargs) :
        results = self.report()
        output_directory = Path(output_directory)
        output_directory = Path(output_directory)
        output_filename = output_directory / '{}.png'.format(self.name)
        plt.cla()
        plt.clf()
        sns.set(style="whitegrid")
        fig, (ax1, ax2) = plt.subplots(2)
        plt.gcf().set_size_inches((6.4,9.6))
        cpu_data_array = np.asarray(self.cpu_percent_data)
        n_cpu = 1 if len(cpu_data_array.shape)==1 else cpu_data_array.shape[-1]
        columns = ['cpu{}'.format(i) for i in range(n_cpu)] if n_cpu > 1 else ['cpu']
        linewidth = 0.75
        cpu_data = pd.DataFrame(
            cpu_data_array, columns=columns
        )
        for col in columns:
            sns.pointplot(x=cpu_data.index, y=col, data=cpu_data, palette="tab10", linewidth=linewidth, ax=ax1)
        ax1.set(xlabel='time (x{0:.2f}s)'.format(self.dt), ylabel='Utilization (%)')
        ax1.set_title("CPU Utilization (%)")

        ax2.set_title("CPU Utilization (%)")
        ax2.boxplot(cpu_data_array, showfliers=False)
        plt.autoscale()
        plt.tight_layout()
        plt.savefig(output_filename)

        plt.gcf().set_size_inches((6.4,4.8)) ## reset back to matplotlib default
        sns.reset_defaults()
        
        return {'cpu_percent' : output_filename}
//  [python]
def plot(self, output_directory, *args, **kwargs) :
        results = self.report()
        output_directory = Path(output_directory)
        output_directory = Path(output_directory)
        output_filename = output_directory / '{}.png'.format(self.name)
        plt.cla()
        plt.clf()
        sns.set(style="whitegrid")
        fig, (ax1, ax2) = plt.subplots(2)
        plt.gcf().set_size_inches((6.4,9.6))
        cpu_data_array = np.asarray(self.cpu_percent_data)
        n_cpu = 1 if len(cpu_data_array.shape)==1 else cpu_data_array.shape[-1]
        columns = ['cpu{}'.format(i) for i in range(n_cpu)] if n_cpu > 1 else ['cpu']
        linewidth = 0.75
        cpu_data = pd.DataFrame(
            cpu_data_array, columns=columns
        )
        sns.lineplot(data=cpu_data, palette="tab10", linewidth=linewidth, dashes=False, ax=ax1)
        ax1.set(xlabel='time (x{0:.2f}s)'.format(self.dt), ylabel='Utilization (%)')
        ax1.set_title("CPU Utilization (%)")

        ax2.set_title("CPU Utilization (%)")
        ax2.boxplot(cpu_data_array, showfliers=False)
        plt.autoscale()
        plt.tight_layout()
        plt.savefig(output_filename)

        plt.gcf().set_size_inches((6.4,4.8)) ## reset back to matplotlib default
        sns.reset_defaults()
        
        return {'cpu_percent' : output_filename}
//  [python]
def plot(
        self,
        controller_under_test: "Controller",
        results_df: pd.DataFrame,
        display_plots: bool = False,
    ) -> List[Tuple[str, figure]]:
        """
        Plot the results, and return the plot handles. Optionally
        display the plots.

        args:
            controller_under_test: the controller with which to run the experiment
            results_df: a DataFrame of results, as returned by `self.run`
            display_plots: defaults to False. If True, display the plots (blocks until
                           the user responds).
        returns: a list of tuples containing the name of each figure and the figure
                 object.
        """
        # Set the color scheme
        sns.set_theme(context="talk", style="white")

        # Plot the state trajectories
        fig, ax = plt.subplots(1, 1)
        fig.set_size_inches(8, 8)
        sns.pointplot(
            ax=ax,
            x="$x$",
            y="$y$",
            style="Parameters",
            hue="Simulation",
            data=results_df,
        )

        # Plot the environment
        controller_under_test.dynamics_model.plot_environment(ax)

        fig_handle = ("HW Rollout (state space)", fig)

        if display_plots:
            plt.show()
            return []
        else:
            return [fig_handle]
//  [python]
def plot(
        self,
        controller_under_test: "Controller",
        results_df: pd.DataFrame,
        display_plots: bool = False,
    ) -> List[Tuple[str, figure]]:
        """
        Plot the results, and return the plot handles. Optionally
        display the plots.

        args:
            controller_under_test: the controller with which to run the experiment
            results_df: a DataFrame of results, as returned by `self.run`
            display_plots: defaults to False. If True, display the plots (blocks until
                           the user responds).
        returns: a list of tuples containing the name of each figure and the figure
                 object.
        """
        # Set the color scheme
        sns.set_theme(context="talk", style="white")

        # Plot the state trajectories
        fig, ax = plt.subplots(1, 1)
        fig.set_size_inches(8, 8)
        sns.lineplot(
            ax=ax,
            x="$x$",
            y="$y$",
            style="Parameters",
            hue="Simulation",
            data=results_df,
        )

        # Plot the environment
        controller_under_test.dynamics_model.plot_environment(ax)

        fig_handle = ("HW Rollout (state space)", fig)

        if display_plots:
            plt.show()
            return []
        else:
            return [fig_handle]
//  [python]
def plot(
        self,
        kind: str = "box",
        what: str = "t_nucleation",
        group: Union[str, Sequence[str]] = "all",
        context: bool = True,
    ):
        """Create plots for Snowflake object.

        Args:
            kind (str, optional): Type of plot to print. If input is
                'trajectories' will print temperature or sigma profile.
                Otherwise will print from stats dict. In that case,
                any sns.catplot 'kind' input is allowed.
                Defaults to "box".
            what (str, optional): What to plot. For trajectories valid inputs are
                sigma or temperature. Otherwise, it's the keys of the stats dict.
                I.e., t_nucleation, T_nucleation, t_solidification.
                Defaults to "temperature".
            group (Union[str, Sequence[str]], optional): Subgroup to return.
                Defaults to "all".
            context (bool, optional): Whether or not to print additional context
                in the figure. Mainly used to add shelf temperature.
        """
        stats_df, traj_df = self.to_frame()
        if kind.lower().startswith("traj"):
            if self._emptyStore:
                raise ValueError("No trajectories have been stored. Cannot plot.")
            df = traj_df
        else:
            df = stats_df

        if group != "all":
            if not isinstance(group, (tuple, list)):
                group = [group]
            df = df[df.group.isin(group)]

        if kind.lower().startswith("traj"):
            df = df[df.state.str.contains(what)]
            if len(df) == 0:
                raise ValueError(
                    f"No data for {what} for plot type {kind} and group {group}. "
                    + "Please check your inputs."
                )
            ax = plt.gca()
            for g in df["group"].unique():
                gdf = df[df["group"] == g]
                plt.plot(gdf["Time"], gdf["value"], label=g)
            plt.xlabel("Time")
            plt.ylabel("value")
            plt.legend()

            if (what == "temperature") and context:
                N_timeSteps = (
                    int(np.ceil(self.opcond.t_tot / self.dt)) + 1
                )  # the total number of timesteps
                t = np.arange(0, N_timeSteps * self.dt, self.dt)
                T_shelf = self.opcond.tempProfile(self.dt)
                plt.plot(
                    t,
                    T_shelf,
                    linestyle="dashed",
                    linewidth=0.75,
                    color="black",
                    label="Shelf Temperature",
                )
                plt.legend()


        else:
            df = df[df.variable.str.contains(what)]
            if len(df) == 0:
                raise ValueError(
                    f"No data for {what} for plot type {kind} and group {group}. "
                    + "Please check your inputs."
                )
            sns.catplot(data=df, hue="group", y="value", kind=kind, x="variable")
//  [python]
def plot(
        self,
        kind: str = "box",
        what: str = "t_nucleation",
        group: Union[str, Sequence[str]] = "all",
        context: bool = True,
    ):
        """Create plots for Snowflake object.

        Args:
            kind (str, optional): Type of plot to print. If input is
                'trajectories' will print temperature or sigma profile.
                Otherwise will print from stats dict. In that case,
                any sns.catplot 'kind' input is allowed.
                Defaults to "box".
            what (str, optional): What to plot. For trajectories valid inputs are
                sigma or temperature. Otherwise, it's the keys of the stats dict.
                I.e., t_nucleation, T_nucleation, t_solidification.
                Defaults to "temperature".
            group (Union[str, Sequence[str]], optional): Subgroup to return.
                Defaults to "all".
            context (bool, optional): Whether or not to print additional context
                in the figure. Mainly used to add shelf temperature.
        """
        stats_df, traj_df = self.to_frame()
        if kind.lower().startswith("traj"):
            if self._emptyStore:
                raise ValueError("No trajectories have been stored. Cannot plot.")
            df = traj_df
        else:
            df = stats_df

        if group != "all":
            if not isinstance(group, (tuple, list)):
                group = [group]
            df = df[df.group.isin(group)]

        if kind.lower().startswith("traj"):
            df = df[df.state.str.contains(what)]
            if len(df) == 0:
                raise ValueError(
                    f"No data for {what} for plot type {kind} and group {group}. "
                    + "Please check your inputs."
                )
            ax = sns.lineplot(data=df, hue="group", y="value", x="Time")

            if (what == "temperature") and context:
                N_timeSteps = (
                    int(np.ceil(self.opcond.t_tot / self.dt)) + 1
                )  # the total number of timesteps
                t = np.arange(0, N_timeSteps * self.dt, self.dt)
                T_shelf = self.opcond.tempProfile(self.dt)
                sns.lineplot(
                    x=t,
                    y=T_shelf,
                    ax=ax,
                    linestyle="dashed",
                    linewidth=0.75,
                    color="black",
                    label="Shelf Temperature",
                )

        else:
            df = df[df.variable.str.contains(what)]
            if len(df) == 0:
                raise ValueError(
                    f"No data for {what} for plot type {kind} and group {group}. "
                    + "Please check your inputs."
                )
            sns.catplot(data=df, hue="group", y="value", kind=kind, x="variable")
//  [python]
def count_cumsum_bal(args):
    # adjust color
    g = sns.lineplot(x=[0], y=[0], linewidth=0)
    g = sns.lineplot(x=[0], y=[0], linewidth=0)
    g = sns.lineplot(x=[0], y=[0], linewidth=0)

    word_counts = np.load(f"{args.meta_index_path}/entry_counts.npy")
    counts = np.sort(word_counts)

    cumsum_counts = np.cumsum(counts)
    y = cumsum_counts.tolist()

    g = sns.lineplot(x=list(range(len(y))), y=y, linewidth=4)
    plt.text(len(y)*0.95, 1.05*y[-1], r"t=$\infty$", horizontalalignment='left', size=18, color="blue")

    pts = [20000, 90000, 170000]

    for t in pts:
        _counts = np.array(counts)
        _counts[_counts > t] = t
        _cumsum = np.cumsum(_counts)
        y = _cumsum.tolist()
        g = sns.lineplot(x=list(range(len(y))), y=y, linewidth=6)
        plt.text(len(y), 1.05*(y[-1]), f"t={t}", horizontalalignment='left', size=18, color="blue")

    ax = plt.gca()
    # Set alpha transparency for the line
    line = ax.lines[-2].set_alpha(0.7)
    line = ax.lines[-1].set_alpha(0.7)  # Get the first line from the plot

    g.set_xlabel(f"Metadata Entries Sorted by Counts", fontsize=16)
    g.set_ylabel("Cumulative Entry Counts", fontsize=16)
    plt.tick_params(
        axis='x',
        which='both',
        bottom=False,
        top=False,
        labelbottom=False
    )
//  [python]
def _plot_multitask_sched_info(self):
        if self.multitask_df is None:
            return

        sched_df = self.multitask_df.copy()
        """
        x = sm_id
        hue = expr
        y:
          for sm_id in all available sm_ids:
            y = len(df[df['sm_id'] == sm_id]['thread_id'].unique())
        """
        plot_df = sched_df[['sm_id', 'expr']].drop_duplicates().reset_index()
        del plot_df['index']

        def _num_threads_using_sm(row):
            thread_ids = sched_df[ \
                (sched_df['sm_id'] == row['sm_id']) \
                & (sched_df['expr'] == row['expr'])] \
                ['thread_id'].unique()
            ret = len(thread_ids)
            return ret
        plot_df['num_threads_using_sm'] = plot_df.apply(_num_threads_using_sm, axis=1)

        titled_df = copy.copy(plot_df)
        col_titles = {
            'expr': 'Configuration',
        }
        titled_df.rename(columns=col_titles, inplace=True)

        sns.set(style="whitegrid")
        # ax = sns.scatterplot(x="sm_id", y="num_threads_using_sm", hue=col_titles["expr"],
        ax = sns.pointplot(x="sm_id", y="num_threads_using_sm", hue=col_titles["expr"],
                             markers=True,
                             style=col_titles["expr"],
                             data=titled_df,
                             markersize=8,
                             # s=4,
                             )
        x_min, x_max = ax.get_xlim()
        # -1 so we can see markers at x=0 without them being cut off.
        ax.set_xlim(-2, NUM_SMS)
        ax.set_ylabel('Number of CPU workers using SM')
        ax.set_xlabel(SM_ID_X_LABEL)
        ax.set_title('Fine-grained SM scheduling of\nmulti-process and multi-thread configurations')
        plt.gcf().subplots_adjust(top=0.90)

        # Q: How to select the "multi-process" line?
        # IDEA: same list index as legend title?
        # ax.lines[3].set_markersize(16)

        # HACK: the "Multi-process" line only has 1 point (x=sm_id=0, y=num_threads_using_sm=60) making it easy to miss...
        # Make it stand out by increasing the markersize of the single point.
        larger_markersize = 14
        should_set_markersize = set([
           # 0, # multi-thread line
           1, # multi-process line
        ])
        for i, line in enumerate(ax.get_lines()):
            if i in should_set_markersize:
                logger.info(f"line[{i}].set_markersize({larger_markersize})")
                line.set_markersize(larger_markersize)

        save_plot(plot_df, _j(self._multitask_dir(), 'multitask_sched_info.svg'))
//  [python]
def _plot_multitask_sched_info(self):
        if self.multitask_df is None:
            return

        sched_df = self.multitask_df.copy()
        """
        x = sm_id
        hue = expr
        y:
          for sm_id in all available sm_ids:
            y = len(df[df['sm_id'] == sm_id]['thread_id'].unique())
        """
        plot_df = sched_df[['sm_id', 'expr']].drop_duplicates().reset_index()
        del plot_df['index']

        def _num_threads_using_sm(row):
            thread_ids = sched_df[ \
                (sched_df['sm_id'] == row['sm_id']) \
                & (sched_df['expr'] == row['expr'])] \
                ['thread_id'].unique()
            ret = len(thread_ids)
            return ret
        plot_df['num_threads_using_sm'] = plot_df.apply(_num_threads_using_sm, axis=1)

        titled_df = copy.copy(plot_df)
        col_titles = {
            'expr': 'Configuration',
        }
        titled_df.rename(columns=col_titles, inplace=True)

        sns.set(style="whitegrid")
        # ax = sns.scatterplot(x="sm_id", y="num_threads_using_sm", hue=col_titles["expr"],
        ax = sns.lineplot(x="sm_id", y="num_threads_using_sm", hue=col_titles["expr"],
                             markers=True,
                             style=col_titles["expr"],
                             data=titled_df,
                             markersize=8,
                             # s=4,
                             )
        x_min, x_max = ax.get_xlim()
        # -1 so we can see markers at x=0 without them being cut off.
        ax.set_xlim(-2, NUM_SMS)
        ax.set_ylabel('Number of CPU workers using SM')
        ax.set_xlabel(SM_ID_X_LABEL)
        ax.set_title('Fine-grained SM scheduling of\nmulti-process and multi-thread configurations')
        plt.gcf().subplots_adjust(top=0.90)

        # Q: How to select the "multi-process" line?
        # IDEA: same list index as legend title?
        # ax.lines[3].set_markersize(16)

        # HACK: the "Multi-process" line only has 1 point (x=sm_id=0, y=num_threads_using_sm=60) making it easy to miss...
        # Make it stand out by increasing the markersize of the single point.
        larger_markersize = 14
        should_set_markersize = set([
           # 0, # multi-thread line
           1, # multi-process line
        ])
        for i, line in enumerate(ax.get_lines()):
            if i in should_set_markersize:
                logger.info(f"line[{i}].set_markersize({larger_markersize})")
                line.set_markersize(larger_markersize)

        save_plot(plot_df, _j(self._multitask_dir(), 'multitask_sched_info.svg'))
//  [python]
def plot(data: list, xlabel: str, ylabel: str, title: str, pth: str = './picture.jpg'):
    """
    Overview:
        Draw training polyline
    Interface:
        data (:obj:`List[Dict]`): the data we will use to draw polylines
            data[i]['step']: horizontal axis data
            data[i]['value']: vertical axis data
            data[i]['label']: the data label
        xlabel (:obj:`str`): the x label name
        ylabel (:obj:`str`): the y label name
        title (:obj:`str`): the title name
    """
    sns.set(style="darkgrid", font_scale=1.5)
    for nowdata in data:
        step, value, label = nowdata['x'], nowdata['y'], nowdata['label']
        plt.plot(step, value, label=label)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.title(title)
    plt.savefig(pth)
//  [python]
def plot(data: list, xlabel: str, ylabel: str, title: str, pth: str = './picture.jpg'):
    """
    Overview:
        Draw training polyline
    Interface:
        data (:obj:`List[Dict]`): the data we will use to draw polylines
            data[i]['step']: horizontal axis data
            data[i]['value']: vertical axis data
            data[i]['label']: the data label
        xlabel (:obj:`str`): the x label name
        ylabel (:obj:`str`): the y label name
        title (:obj:`str`): the title name
    """
    sns.set(style="darkgrid", font_scale=1.5)
    for nowdata in data:
        step, value, label = nowdata['x'], nowdata['y'], nowdata['label']
        sns.lineplot(x=step, y=value, label=label)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.title(title)
    plt.savefig(pth)
//  [python]
def generate_plots(preprocessed_input):
    """
    Create some visualizations of the data.

    Args:

    preprocessed_input: path where of the output from clean_data
    """
    import os

    import seaborn as sns

    df = pd.read_parquet(preprocessed_input)
    df['datetime'] = df['datetime'].apply(pd.Timestamp)
    df_weekly = convert_to_weekly(df)

    sns.set(font_scale=2)
    grid = sns.FacetGrid(
        df_weekly,
        col="counting_station",
        hue="counting_station",
        palette="tab20c",
        col_wrap=4,
        height=3,
        aspect=3)
    grid.map(plt.plot, "datetime", "velo_in")
    grid.map(plt.plot, "datetime", "velo_out")
    grid.map(plt.axhline, y=0, ls=":", c=".5")
    grid.set_xticklabels(rotation=30)

    # check if the figures exist already. If so, remove them
    remove_if_exists('figs/grid_plot.png')
    plt.savefig('figs/grid_plot.png')

    f = plt.figure(figsize=(15,10))
    sns.set(rc={'figure.figsize': (15, 10)})
    sns.pointplot(
        x="datetime", y="velo_all", hue="counting_station", data=df_weekly)
    remove_if_exists('figs/cumulative.png')
    plt.savefig('figs/cumulative.png')
//  [python]
def generate_plots(preprocessed_input):
    """
    Create some visualizations of the data.

    Args:

    preprocessed_input: path where of the output from clean_data
    """
    import os

    import seaborn as sns

    df = pd.read_parquet(preprocessed_input)
    df['datetime'] = df['datetime'].apply(pd.Timestamp)
    df_weekly = convert_to_weekly(df)

    sns.set(font_scale=2)
    grid = sns.FacetGrid(
        df_weekly,
        col="counting_station",
        hue="counting_station",
        palette="tab20c",
        col_wrap=4,
        height=3,
        aspect=3)
    grid.map(plt.plot, "datetime", "velo_in")
    grid.map(plt.plot, "datetime", "velo_out")
    grid.map(plt.axhline, y=0, ls=":", c=".5")
    grid.set_xticklabels(rotation=30)

    # check if the figures exist already. If so, remove them
    remove_if_exists('figs/grid_plot.png')
    plt.savefig('figs/grid_plot.png')

    f = plt.figure(figsize=(15,10))
    sns.set(rc={'figure.figsize': (15, 10)})
    sns.lineplot(
        x="datetime", y="velo_all", hue="counting_station", data=df_weekly)
    remove_if_exists('figs/cumulative.png')
    plt.savefig('figs/cumulative.png')
//  [python]
plt.subplot(1, 2, 1)
sns.countplot(data['main_product_code'], palette = 'plasma')
plt.title('Checking counts of Main Product', fontsize = 20)

# checking dependency with the target variable
plt.subplot(1, 2, 2)
sns.pointplot(train['main_product_code'], y_train)
//  [python]
plt.subplot(1, 2, 1)
sns.countplot(data['main_product_code'], palette = 'plasma')
plt.title('Checking counts of Main Product', fontsize = 20)

# checking dependency with the target variable
plt.subplot(1, 2, 2)
sns.lineplot(train['main_product_code'], y_train)
//  [python]
def _plot_individual(df, language):
  """Plots individual language."""
  ax = sns.tsplot(x="order", y="entropy",
                    data=df[df["language"] == language])
  ax.set(ylabel=_plot_ylabel())
  fig = ax.get_figure()
  plot_file = os.path.join(FLAGS.output_plots_dir,
                           language + "_%s.pdf" % _plot_filename_suffix())
  logging.info(f"Saving {plot_file} ...")
  fig.savefig(plot_file, bbox_inches="tight", dpi=600)
  fig.clear()
//  [python]
def _plot_individual(df, language):
  """Plots individual language."""
  ax = sns.lineplot(x="order", y="entropy",
                    data=df[df["language"] == language])
  ax.set(ylabel=_plot_ylabel())
  fig = ax.get_figure()
  plot_file = os.path.join(FLAGS.output_plots_dir,
                           language + "_%s.pdf" % _plot_filename_suffix())
  logging.info(f"Saving {plot_file} ...")
  fig.savefig(plot_file, bbox_inches="tight", dpi=600)
  fig.clear()
//  [python]
def get_schoopy_plot(table, error_bars=True):
    fig, ax = plt.subplots(figsize=(20, 9))

    models = set(table.model)
    test_datas = set(table.test_data)
    alphas = set(table.alpha)

    sns.tsplot(data=table,
                 time="test_iter",
                 value="test_acc_mean",
                 condition="model",
                 unit="alpha",
                 err_style="band",
                 interpolate=True,
                 size="alpha",
                 sizes=(2, 8),
                 condition2="test_data" if len(test_datas) > 1 else None,
                 color="dark",
                 legend=True,
                 ax=ax)

    if error_bars and "test_acc_sem" in table.keys():
        for model in models:
            for test_data in test_datas:
                for alpha in alphas:
                    data = table[(table.model == model) &
                                 (table.test_data == test_data) &
                                 (table.alpha == alpha)]
                    plt.fill_between(data.test_iter,
                                     data.test_acc_mean - data.test_acc_sem,
                                     data.test_acc_mean + data.test_acc_sem,
                                     alpha=0.1, color="k")

    tr = table.max_iters.max()  # training regime number
    ax.fill_between([0, tr], [105, 105], alpha=0.3, label="Training Regime")
    return ax
//  [python]
def get_schoopy_plot(table, error_bars=True):
    fig, ax = plt.subplots(figsize=(20, 9))

    models = set(table.model)
    test_datas = set(table.test_data)
    alphas = set(table.alpha)

    sns.lineplot(data=table,
                 x="test_iter",
                 y="test_acc_mean",
                 hue="model",
                 size="alpha",
                 sizes=(2, 8),
                 style="test_data" if len(test_datas) > 1 else None,
                 palette="dark",
                 dashes=True,
                 units=None,
                 legend="auto",
                 ax=ax)

    if error_bars and "test_acc_sem" in table.keys():
        for model in models:
            for test_data in test_datas:
                for alpha in alphas:
                    data = table[(table.model == model) &
                                 (table.test_data == test_data) &
                                 (table.alpha == alpha)]
                    plt.fill_between(data.test_iter,
                                     data.test_acc_mean - data.test_acc_sem,
                                     data.test_acc_mean + data.test_acc_sem,
                                     alpha=0.1, color="k")

    tr = table.max_iters.max()  # training regime number
    ax.fill_between([0, tr], [105, 105], alpha=0.3, label="Training Regime")
    return ax
//  [python]
def plot_noise_bits(model, noise_bits, run_name, setting):
    print(f"Plotting noise bits {setting}")
    plt.figure(figsize=(5, 3.5))
    plot = sns.tsplot(time=range(len(noise_bits)), data=noise_bits)
    plot.set_title(f"{model}".capitalize() + f" Noise Bits by Layer, {setting}")
    plot.set(xlabel="Layer", ylabel=f"Noise Bits")
    plt.yticks([3, 4, 5, 6, 7])
    plt.savefig(f"{run_name}/noise_bits_{setting.split()[0]}.pdf", bbox_inches="tight")
    plt.close()
//  [python]
def plot_noise_bits(model, noise_bits, run_name, setting):
    print(f"Plotting noise bits {setting}")
    plt.figure(figsize=(5, 3.5))
    plot = sns.lineplot(x=range(len(noise_bits)), y=noise_bits)
    plot.set_title(f"{model}".capitalize() + f" Noise Bits by Layer, {setting}")
    plot.set(xlabel="Layer", ylabel=f"Noise Bits")
    plt.yticks([3, 4, 5, 6, 7])
    plt.savefig(f"{run_name}/noise_bits_{setting.split()[0]}.pdf", bbox_inches="tight")
    plt.close()
//  [python]
def plot_lines_list(xy_datas: List[pd.DataFrame],
                    data_labels: List[List[str]],
                    colors: List[str] = None,
                    is_fill_annotations: bool = False,
                    xvar_format: str = '{:.1f}',
                    yvar_format: str = '{:.1f}',
                    xlabel: str = None,
                    ylabel: str = None,
                    title: str = None,
                    fontsize: int = 10,
                    x_limits: Tuple[Union[float, None], Union[float, None]] = None,
                    y_limits: Tuple[Union[float, None], Union[float, None]] = None,
                    ax: plt.Subplot = None,
                    **kwargs
                    ) -> plt.Figure:
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = None

    if colors is None:
        colors = put.get_n_colors(n=len(xy_datas))

    for xy, color, labels in zip(xy_datas, colors, data_labels):
        s.plot(x=xy.columns[0], y=xy.columns[1], data=xy, marker='None', color=color, ax=ax)

        for label, x, y in zip(labels, xy.iloc[:, 0].to_numpy(), xy.iloc[:, 1].to_numpy()):

            if label != '':
                # very specific to blended portfolios
                port_weight = label[-4:]
                if port_weight == '100%':
                    x_offset = 40  # 100 portfolios are shifted to right
                    y_offset = 0
                elif port_weight in ['-50%', ' 60%']:
                    x_offset = 40
                    y_offset = 15
                elif port_weight == '0-0%':
                    x_offset = 40
                    y_offset = 30
                else:
                    x_offset = 1
                    y_offset = 1

                if is_fill_annotations:
                    ax.annotate(
                        label,
                        xy=(x, y), xytext=(x_offset, y_offset),
                        textcoords='offset points', ha='right', va='bottom',
                        bbox=dict(boxstyle='round, pad=0.5', fc='blue', alpha=0.75),
                        arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'),
                        fontsize=fontsize)
                else:
                    ax.annotate(
                        label,
                        xy=(x, y), xytext=(x_offset, y_offset),
                        textcoords='offset points', ha='right', va='bottom',
                        fontsize=fontsize)

    if y_limits is not None:
        put.set_y_limits(ax=ax, y_limits=y_limits)

    if x_limits is not None:
        put.set_x_limits(ax=ax, x_limits=x_limits)

    put.set_ax_ticks_format(ax=ax, fontsize=fontsize, xvar_format=xvar_format, yvar_format=yvar_format)
    put.set_ax_xy_labels(ax=ax, xlabel=xlabel, ylabel=ylabel, fontsize=fontsize, **kwargs)

    if title is not None:
        put.set_title(ax=ax, title=title, fontsize=fontsize)

    put.set_spines(ax=ax, **kwargs)

    return fig
//  [python]
def plot_lines_list(xy_datas: List[pd.DataFrame],
                    data_labels: List[List[str]],
                    colors: List[str] = None,
                    is_fill_annotations: bool = False,
                    xvar_format: str = '{:.1f}',
                    yvar_format: str = '{:.1f}',
                    xlabel: str = None,
                    ylabel: str = None,
                    title: str = None,
                    fontsize: int = 10,
                    x_limits: Tuple[Union[float, None], Union[float, None]] = None,
                    y_limits: Tuple[Union[float, None], Union[float, None]] = None,
                    ax: plt.Subplot = None,
                    **kwargs
                    ) -> plt.Figure:
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = None

    if colors is None:
        colors = put.get_n_colors(n=len(xy_datas))

    for xy, color, labels in zip(xy_datas, colors, data_labels):
        sns.lineplot(x=xy.columns[0], y=xy.columns[1], data=xy, marker='None', color=color, ax=ax)

        for label, x, y in zip(labels, xy.iloc[:, 0].to_numpy(), xy.iloc[:, 1].to_numpy()):

            if label != '':
                # very specific to blended portfolios
                port_weight = label[-4:]
                if port_weight == '100%':
                    x_offset = 40  # 100 portfolios are shifted to right
                    y_offset = 0
                elif port_weight in ['-50%', ' 60%']:
                    x_offset = 40
                    y_offset = 15
                elif port_weight == '0-0%':
                    x_offset = 40
                    y_offset = 30
                else:
                    x_offset = 1
                    y_offset = 1

                if is_fill_annotations:
                    ax.annotate(
                        label,
                        xy=(x, y), xytext=(x_offset, y_offset),
                        textcoords='offset points', ha='right', va='bottom',
                        bbox=dict(boxstyle='round, pad=0.5', fc='blue', alpha=0.75),
                        arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'),
                        fontsize=fontsize)
                else:
                    ax.annotate(
                        label,
                        xy=(x, y), xytext=(x_offset, y_offset),
                        textcoords='offset points', ha='right', va='bottom',
                        fontsize=fontsize)

    if y_limits is not None:
        put.set_y_limits(ax=ax, y_limits=y_limits)

    if x_limits is not None:
        put.set_x_limits(ax=ax, x_limits=x_limits)

    put.set_ax_ticks_format(ax=ax, fontsize=fontsize, xvar_format=xvar_format, yvar_format=yvar_format)
    put.set_ax_xy_labels(ax=ax, xlabel=xlabel, ylabel=ylabel, fontsize=fontsize, **kwargs)

    if title is not None:
        put.set_title(ax=ax, title=title, fontsize=fontsize)

    put.set_spines(ax=ax, **kwargs)

    return fig
//  [python]
def plot_bitwidths(model, run_name, mode, model_name, round_bitwidth):
    bitwidths = get_bitwidths(model, round_bitwidth)

    plt.figure()
    plot = sns.tsplot(x=range(len(bitwidths["w_bits"])), y=bitwidths["w_bits"])
    plot.set_title(f"{model_name}".capitalize() + f" Weight Bits by Layer {mode}")
    plot.set(xlabel="Layer")
    plt.savefig(f"{run_name}/wb_{mode}.pdf")
    plt.close()

    plt.figure()
    plot = sns.tsplot(x=range(len(bitwidths["a_bits"])), y=bitwidths["a_bits"])
    plot.set_title(f"{model_name}".capitalize() + f" Activation Bits by Layer {mode}")
    plot.set(xlabel="Layer")
    plt.savefig(f"{run_name}/ab_{mode}.pdf")
    plt.close()
//  [python]
def plot_bitwidths(model, run_name, mode, model_name, round_bitwidth):
    bitwidths = get_bitwidths(model, round_bitwidth)

    plt.figure()
    plot = sns.lineplot(x=range(len(bitwidths["w_bits"])), y=bitwidths["w_bits"])
    plot.set_title(f"{model_name}".capitalize() + f" Weight Bits by Layer {mode}")
    plot.set(xlabel="Layer")
    plt.savefig(f"{run_name}/wb_{mode}.pdf")
    plt.close()

    plt.figure()
    plot = sns.lineplot(x=range(len(bitwidths["a_bits"])), y=bitwidths["a_bits"])
    plot.set_title(f"{model_name}".capitalize() + f" Activation Bits by Layer {mode}")
    plot.set(xlabel="Layer")
    plt.savefig(f"{run_name}/ab_{mode}.pdf")
    plt.close()
//  [python]
plt.figure(figsize = (15, 7))
sns.countplot(df['MONTH'])


# **Round trips for every purpose every month?**

# In[53]:


pd.set_option('display.max_rows',None)


# In[54]:


df.groupby(['MONTH','PURPOSE'])['ROUND_TRIP'].count()


# **Minutes taken to cover miles?**

# In[55]:


sns.regplot(data = df, x = df['MINUTES'], y = df['MILES'])
//  [python]
plt.figure(figsize = (15, 7))
sns.countplot(df['MONTH'])


# **Round trips for every purpose every month?**

# In[53]:


pd.set_option('display.max_rows',None)


# In[54]:


df.groupby(['MONTH','PURPOSE'])['ROUND_TRIP'].count()


# **Minutes taken to cover miles?**

# In[55]:


sns.lineplot(data = df, x = df['MINUTES'], y = df['MILES'])
//  [python]
def output_figure2():
    for alg, score in alg_score_list:
        for dataset in dataset_list:
            input_path = "out/result-all.csv"
            df = pd.read_csv(input_path)
            df = df[df["alg"] == alg]
            df = df[df["score"] == score]
            df = df[df["d"] == dataset]

            df = df[['iter', 'exist_prior', 'exist_prior_wrong',
                    'forb_prior', 'forb_prior_wrong']]

            df["wrong_prior"] = df["exist_prior_wrong"] + \
                df["forb_prior_wrong"]
            df["prior_num"] = df["exist_prior"] + df["forb_prior"]

            # save to csv
            df = df[['iter', 'prior_num', 'wrong_prior']]
            df.to_csv(
                f"out/paper/figure2/figure2-{alg}-{score}-{dataset}.csv", index=False)
            # melt
            df_melted = df.melt(
                id_vars='iter', var_name='metric', value_name='value')
            sns.tsplot(x="iter", y="value", hue="metric",
                         data=df_melted, palette=sns.color_palette())
            plt.savefig(
                f"img/figure2/{alg}-{score}-{dataset}.png")
            plt.close()
//  [python]
def output_figure2():
    for alg, score in alg_score_list:
        for dataset in dataset_list:
            input_path = "out/result-all.csv"
            df = pd.read_csv(input_path)
            df = df[df["alg"] == alg]
            df = df[df["score"] == score]
            df = df[df["d"] == dataset]

            df = df[['iter', 'exist_prior', 'exist_prior_wrong',
                    'forb_prior', 'forb_prior_wrong']]

            df["wrong_prior"] = df["exist_prior_wrong"] + \
                df["forb_prior_wrong"]
            df["prior_num"] = df["exist_prior"] + df["forb_prior"]

            # save to csv
            df = df[['iter', 'prior_num', 'wrong_prior']]
            df.to_csv(
                f"out/paper/figure2/figure2-{alg}-{score}-{dataset}.csv", index=False)
            # melt
            df_melted = df.melt(
                id_vars='iter', var_name='metric', value_name='value')
            sns.lineplot(x="iter", y="value", hue="metric",
                         data=df_melted, palette=sns.color_palette())
            plt.savefig(
                f"img/figure2/{alg}-{score}-{dataset}.png")
            plt.close()
//  [python]
def output_figure3():
    for alg, score in alg_score_list:
        for dataset in dataset_list:
            input_path = "out/result-all.csv"
            df = pd.read_csv(input_path)
            df = df[df["alg"] == alg]
            df = df[df["score"] == score]
            df = df[df["d"] == dataset]

            df = df[['iter', 'tpr', 'norm_shd']]
            df = df.rename(columns={"tpr": "TPR", "norm_shd": "SHD"})
            df["SHD"] = df["SHD"].round(4)
            df.to_csv(
                f"out/paper/figure3/figure3-{alg}-{score}-{dataset}.csv", index=False)
            # melt
            df_melted = df.melt(
                id_vars='iter', var_name='metric', value_name='value')
            sns.pointplot(x="iter", y="value", hue="metric",
                         data=df_melted, palette=sns.color_palette(), join=True)
            plt.savefig(
                f"img/figure3/{alg}-{score}-{dataset}.png")
            plt.close()
            rprint(
                f"📊 Iter-tpr lineplot saved to [italic blue]{alg}-{score}-{dataset}.png[/italic blue]")