Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (16.4k points)

I need to know, whether it is possible to make the Bland-Altman plot in Python? After a huge effort, I couldn't able to find anything about it.

The alternate name for this plot is Turkey mean-difference plot

For Example:

1 Answer

0 votes
by (26.4k points)

The following code will provide basic plotting, Ultimately on your needs, you can configure it.

import matplotlib.pyplot as plt

import numpy as np

def bland_altman_plot(data1, data2, *args, **kwargs):

    data1     = np.asarray(data1)

    data2     = np.asarray(data2)

    mean      = np.mean([data1, data2], axis=0)

    diff      = data1 - data2                   # Difference between data1 and data2

    md        = np.mean(diff)                   # Mean of the difference

    sd        = np.std(diff, axis=0)            # Standard deviation of the difference

    plt.scatter(mean, diff, *args, **kwargs)

    plt.axhline(md,           color='gray', linestyle='--')

    plt.axhline(md + 1.96*sd, color='gray', linestyle='--')

    plt.axhline(md - 1.96*sd, color='gray', linestyle='--')

In the above code, data1 & data2 are used for calculating the coordinates for the points which are plotted

Also, you can create a plot by executing the following code:

from numpy.random import random

bland_altman_plot(random(10), random(10))

plt.title('Bland-Altman Plot')

To learn more about python: Come & join: Python course

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories