簡體   English   中英

如何在matplotlib散點圖中繪制相關線?

[英]How to draw a correlation line in a matplotlib scatter plot?

下面是我要繪制的散點圖的代碼。 一旦繪制了子圖,我想添加一條相關線。 盡管代碼正在正常運行,但是在繪圖中看不到任何線條。 任何幫助都感激不盡。

    fig, ax = plt.subplots(figsize=fs)
    for g in np.unique(group):
        ix = np.where(group == g)
        sc = ax.scatter(y[ix], dosage[ix], color = cdict[g], edgecolors='none')
    # Fit with polyfit
    b, m = polyfit(y, dosage, 1)
    ax.plot(y, b + m * y, '-')
    ax.set_xlabel('LT2', fontsize = 16)
    ax.set_ylabel('Log Dosage', fontsize = 16)
    # ax.legend(scatterpoints = 1, title='DILI Risk')

    # fig.colorbar(sc, label='Dosage/mg/day')
    path_dose = 'figure/reports/images/{}_hist_dose.png'.format(name_rep)
    data['hist_dosage'].append(path_dose)
    plt.savefig(path_dose)
    plt.close()

以下是我得到的情節。 在此輸入圖像描述

抱歉,我的數據中包含Nans。 np.polyfit()最初不起作用,因此沒有要繪制的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM