Визуализация на html с помощью Django / matplotlib

Я создал приложение на Django, используя свою базу данных, У меня есть график, я могу показать свой график с помощью matplotlib. Что я должен добавить в мой код, чтобы увидеть график на моем results.html?

views.py:


def inf_norm_detection(df_abs, crop_left, crop_right, clean_param=500):
    ''' infinum norm outlier detection, it is the first step of outlier detection
    computes matrix of inf norm (max of absolute values) of the samples one to onother
    inputs: clean_param (int) - usualy 150-500, smaller means more outliers,
            df_abs (pandas DataFrame) - data of interest, usualy absorbance or asmptotic data
            crop_left, crop_right - values to crop the data according to MPF measurments.
    output: indexes of df_abs that are suspected to be outliers, if none were identified, None is returned
    '''
    X = df_abs.iloc[:, crop_left:crop_right].to_numpy()
    l = X.shape[0]
    D = np.zeros((l, l))
    idx = range(len(X))
    for j in range(1, X.shape[0]):
        idx = list(set(idx) - {j})
        A = X[idx] - X[j]
        D[j, idx] = np.abs(A).max(1)
    D = np.maximum(D, D.transpose())
    d = D.sum(0) / l

    diff = np.sort(d)[1:] - np.sort(d)[:-1]
    if np.where(diff > clean_param * np.median(diff))[0].size != 0:
        threshold = np.sort(d)[np.where(diff > clean_param * np.median(diff))[0] + 1].min()
        return df_abs.iloc[np.where(d >= threshold)].index

def show_absorbance(df_abs, crop_left, crop_right, clean_param):

    outliers = inf_norm_detection(df_abs,crop_left, crop_right, clean_param)
    colors = [color for color in mcolors.CSS4_COLORS.values() if color !='yellow']

    plt.figure(figsize=(16, 10))
    plt.subplot(221)
    plt.plot(df_abs.to_numpy()[:, 1:].T, 'yellow')
    for i, outlier in enumerate(outliers):
        plt.plot(df_abs.loc[outlier].iloc[1:],  c=colors[i],label= outlier)
        plt.legend()
    plt.show()

мой шаблон results.html

<!DOCTYPE html>
<html lang"en">
    
<head></head>
<body></body>
</html>

Вернуться на верх