'Is there a way to compare lists of gradients?

I have evenly spaced time-series graphs with years on the x-axis (2000, 2001, 2002, 2003,..2010) and no. of patients who visited clinics A, B, C, and D on the y-axis (in four separate graphs). I want to compare the difference in the growth of clinics. I calculated the gradient of the list of the no. of patients visited using np.gradient() for each clinic. I'm not sure how to compare the list of slopes (change in the no. of patients over time).

This is sample data and the calculated gradients.

year = [2000, 2001, 2002, 2003]

A = [12, 14, 36, 45]
np.gradient(A) 
array([ 2. , 12. , 15.5,  9. ])

B = [2, 10, 8, 24]
np.gradient(B)
array([ 8.,  3.,  7., 16.])

C = [8, 8, 15, 14]
np.gradient(C)
array([ 0. ,  3.5,  3. , -1. ])

D = [0, 12, 0, 6]
np.gradient(D)
array([12.,  0., -3.,  6.])

Any help is appreciated.



Solution 1:[1]

You could use matplotlib to create a rough sketch of four arrays on a graph to compare the data.

import matplotlib.pyplot as plt

plt.plot(A)
plt.plot(B)
plt.plot(C)
plt.plot(D)
plt.show()

You would have to construct the figure based on your year data and the amount of people which would then create the slops.

or use the gradients: import matplotlib.pyplot as plt

plt.plot(np.gradient(A))
plt.plot(np.gradient(B))
plt.plot(np.gradient(C))
plt.plot(np.gradient(D))
plt.show()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tylerjames