//  [python]
def plot_data(data,
              dir_index,
              ax,
              legend_flag,
              xaxis='Epoch',
              value="AverageEpRet",
              condition="Condition1",
              smooth=1, color='r',
              nrow=1,
              **kwargs):
    if smooth > 1:
        """
        smooth data with moving window average.
        that is,
            smoothed_y[t] = average(y[t-k], y[t-k+1], ..., y[t+k-1], y[t+k])
        where the "smooth" param is width of that window (2k+1)
        """
        y = np.ones(smooth)
        for datum in data:
            x = np.asarray(datum[value])
            z = np.ones(len(x))
            smoothed_x = np.convolve(x, y, 'same') / np.convolve(z, y, 'same')
            datum[value] = smoothed_x

    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)

    sns.set(style="darkgrid", font_scale=2)
    # value = "AverageEpisodeReward"
    sns.tsplot(data=data,
               time=xaxis,
               value=value, unit="Unit",
               condition=condition,
               legend=legend_flag,
               ci='sd',
               color=COLORS,
               linewidth=4,
               ax=ax,
               **kwargs)
    # true 将会在x轴显示abc.
    reach_flag = False
    # 下面是根据第一层第二层，以及每一列，设置x/y轴标签，title等细节，根据需要自己定制。
    if nrow == 1:
        x_label = ''
        # 设置x轴的单位，可以注释掉
        ax.set_xlabel(x_label, fontsize=FontSize)
    elif nrow == 2:
        if reach_flag:
            x_label = xaxis + '\n\n(' + chr(dir_index+97) +')'
        else:
            x_label = xaxis
        ax.set_xlabel(x_label, fontsize=FontSize)
    if nrow == 1:
        if dir_index == 0:
            # 这个TD3和SAC是定制的，可以删掉或者重写，甚至不需要y轴标签的话，整句话注释掉
            ax.set_ylabel(value+"-TD3", fontsize=FontSize+4)
            # 是否给子图加标题，不同层和列的需求不一样，根据需求添加
            title_str = 'title in first'
        else:
            title_str = 'title in second ' + str(dir_index*5) + ' Degrees'
            ax.set_ylabel('', fontsize=0)    
        ax.set_title(title_str)
    else:
        if dir_index == 0:
            # ax.set_ylabel(value+"-SAC-AUTO", fontsize=FontSize+4)
            ax.set_ylabel(value+"-SAC", fontsize=FontSize+4)
        else:
            ax.set_ylabel('', fontsize=FontSize+4)    
    # plt.legend(bbox_to_anchor=(0.05, 1), loc=1, borderaxespad=0.)
    ax.tick_params(
        axis='x',  # changes apply to the x-axis
        labelsize=FontSize + 3
    )
    ax.tick_params(
        axis='y',  # changes apply to the x-axis
        labelsize=FontSize + 3
    )
    # 下面的是将legend放在最后一张子图的左下角
    # plt.legend(loc='lower right', ncol=2, handlelength=2,
    #            borderaxespad=0., prop={'size': FontSize})
    # 下面是将legend放在整张图的下面居中，更好看一些
    plt.legend(bbox_to_anchor=(0.2, -0.3), ncol=4, handlelength=1,
               borderaxespad=0., prop={'size': FontSize})

    xscale = np.max(np.asarray(data[xaxis])) > 5e3    
    if xscale:
        # Just some formatting niceness: x-axis scale in scientific notation if max x is large
        ax.ticklabel_format(style='sci', axis='x', scilimits=(0, 0), labelsize=FontSize)
        if nrow == 2:
            ax.xaxis.offsetText.set_fontsize(FontSize + 3)
        else:
            ax.xaxis.offsetText.set_fontsize(0)    
    # 加栅格，和栅格的透明度
    ax.grid(True, alpha=0.4)