Reputation: 111
I have two data sets, and need to create the ecdf plot, which I have done by:
# sample data
df1000=np.random.exponential(1, 1000)
df10000= np.random.exponential(1, 10000)
def ecdf(data):
"""Generate x and y values for plotting an ECDF."""
return np.sort(data), np.arange(1, len(data)+1) / len(data)
x_1000, y_1000 = ecdf(df1000)
x_10000, y_10000 = ecdf(df10000)
figure(figsize=(8, 6), dpi=300)
a=plt.step(x_1000,y_1000, label="1000",color="green")
d=plt.step(x_10000,y_10000, label="10000",color="blue")
plt.xlabel('Number of Cells', fontsize=18)
plt.ylabel('Proportion', fontsize=18)
plt.title("Type 1", fontsize=18)
plt.legend( loc ="lower right", fontsize=18)
After that I need to callculate confidence interval, which I use this code:
import numpy as np
import scipy.stats
def mean_confidence_interval(data, confidence=0.95):
a = 1.0 * np.array(data)
n = len(a)
m, se = np.mean(a), scipy.stats.sem(a)
h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1)
return m, m-h, m+h,h
CI1000=mean_confidence_interval(df1000, \
confidence=0.95)
CI10000=mean_confidence_interval(df10000, \
confidence=0.95)
next step is to plot confidence_interval along side the my main ECDF plot which I have done it by this code:
figure(figsize=(8, 6), dpi=300)
a=plt.step(x_1000,y_1000, label="1000",color="green")
b=plt.step(x_1000,y_1000-CI1000[3],color="greenyellow")
c=plt.step(x_1000,y_1000+CI1000[3],color="greenyellow")
#plt.fill_between(x_10000,a,b, step="pre", alpha=0.4)
d=plt.step(x_10000,y_10000, label="10000",color="blue")
e=plt.step(x_10000,y_10000-CI1000[3],color="royalblue")
f=plt.step(x_10000,y_10000+CI1000[3],color="royalblue")
plt.xlabel('Number of Cells', fontsize=18)
plt.ylabel('Proportion', fontsize=18)
plt.title("Type 1", fontsize=18)
plt.legend( loc ="lower right", fontsize=18)
What I want to do is to fillout between confidence_interval and main ECDF plots.
I tried to use plt.fill_between(x_10000,a,b, step="pre", alpha=0.4)
but I am getting this error message:
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
How can I solve this problem?
Thank you for your help.
Upvotes: 0
Views: 218
Reputation: 13135
As you can read from the documentation, fill_between
requires numerical data, whereas you are giving it a, b
which are two lists, containing the artists of the lines.
The following will do the trick:
plt.fill_between(x_1000, y_1000, y_1000-CI1000[3], step="pre", alpha=0.4)
Upvotes: 0