<jupyter_start><jupyter_text>Analysis - boxplots<jupyter_code>def boxplots(data_list, which, sort=True, force_finite=False):
    """
    Given a list of results dictionaries and an attribute, makes a boxplot of each of the dictionary's data.
    Note: does not call plt.show()
    
    Parameters:
        data_list: list of results dictionaries.
        which (str): which item in the dictionary to plot.
        sort (bool): default True; if True, sort the datasets in descending order by median.
        force_finite (bool): default False; if True, remove any Inf or NaN values in the datasets before plotting.
    """
    names = np.array([str(item['id'])+': '+' '.join(item['experiment'][1:]) for item in data_list])
    data = [item[which] for item in data_list]
    if force_finite:
        #Remove any inf or nan values
        data = [np.array(item) for item in data]
        data = [item[np.isfinite(item)] for item in data]
    firstlen = len(data[0])
    same_len = np.all([firstlen == len(item) for item in data])
    if same_len:
        data_array = np.array(data)
        if sort:
            means = np.median(data_array,axis=1)
            order = np.argsort(means).astype(int)
        else:
            order = np.arange(data_array.shape[0]).astype(int)
        plt.boxplot(data_array[order,:].T, labels=names[order], vert=False)
    else:
        if sort:
            means = [np.median(item) for item in data]
            order = np.argsort(means).astype(int)
            data = [data[i] for i in order]
            names = [names[i] for i in order]
            
        plt.boxplot(data, labels=names, vert=False)
boxplots(results_split['lorenz'], 'continue')
plt.suptitle('Lorenz system - continue prediction')
plt.show()
boxplots(results_split['lorenz'], 'random')
plt.suptitle('Lorenz system - random prediction')
plt.show()
boxplots(results_split['rossler'], 'continue')
plt.suptitle('Rossler system - continue prediction')
plt.show()
boxplots(results_split['rossler'], 'random')
plt.suptitle('Rossler system - random prediction')
plt.show()
boxplots(results_split['rossler'], 'lyapunov',force_finite=True)
plt.suptitle('Rossler system Lyapunov exponent estimate')
plt.xlim(-0.5,0.5)
plt.show()
boxplots(results_split['thomas'], 'continue')
plt.suptitle('Thomas system - continue prediction')
plt.show()
boxplots(results_split['thomas'], 'random')
plt.suptitle('Thomas system - random prediction')
plt.show()
boxplots(results_split['softrobot'], 'continue')
plt.suptitle('Soft robot system - continue prediction')
plt.show()
boxplots(results_split['softrobot'], 'random')
plt.suptitle('Soft robot system - random prediction')
plt.show()
boxplots(results_split['softrobot'], 'lyapunov')
plt.suptitle('Soft robot Lyapunov exponent estimate')
plt.xlim(-0.2,0.2)
plt.show()<jupyter_output><empty_output>