utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:saw_release 作者: kovibalu 项目源码 文件源码
def plot_2D_arrays(arrs, title='', xlabel='', xinterval=None, ylabel='', yinterval=None, line_names=[], simplified=False):
    """ Plots multiple arrays in the same plot based on the specifications. """
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    import seaborn as sns

    plt.clf()
    sns.set_style('darkgrid')
    sns.set(font_scale=1.5)
    sns.set_palette('husl', 8)

    for i, arr in enumerate(arrs):
        if arr.ndim != 2 or arr.shape[1] != 2:
            raise ValueError(
                'The array should be 2D and the second dimension should be 2!'
                ' Shape: %s' % str(arr.shape)
            )

        # Plot last one with black
        if i == len(arrs) - 1:
            plt.plot(arr[:, 0], arr[:, 1], color='black')
        else:
            plt.plot(arr[:, 0], arr[:, 1])

    # If simplified, we don't show text anywhere
    if not simplified:
        plt.title(title[:30])
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        if line_names:
            plt.legend(line_names, loc=6, bbox_to_anchor=(1, 0.5))

    if xinterval:
        plt.xlim(xinterval)
    if yinterval:
        plt.ylim(yinterval)

    plt.tight_layout()


###############
# String handling
###############
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号