In [1]:
import pandas as pd

data = pd.read_csv("effort.csv")

data = data[["5%", "Expected", "95%"]]
In [2]:
d={"5%": [0], "95%": [0], "Expected": [0]}
data = data.append(pd.DataFrame(d, index=[len(data)], columns=["5%", "Expected", "95%"]))
data
Out[2]:
5% Expected 95%
0 4 5 25
1 2 4 15
2 4 5 18
3 2 3 14
4 2 3 13
5 2 4 14
6 2 3 14
7 2 3 17
8 1 2 10
9 1 3 10
10 0 0 0

11 rows × 3 columns

In [3]:
data['Truth']  = len(data.index) - pd.Series(data.index) - 1
data
Out[3]:
5% Expected 95% Truth
0 4 5 25 10
1 2 4 15 9
2 4 5 18 8
3 2 3 14 7
4 2 3 13 6
5 2 4 14 5
6 2 3 14 4
7 2 3 17 3
8 1 2 10 2
9 1 3 10 1
10 0 0 0 0

11 rows × 4 columns

In [4]:
data['index'] = data.index
data_lng = pd.melt(data[["index", "Expected", "Truth"]], id_vars='index')
data_lng
Out[4]:
index variable value
0 0 Expected 5
1 1 Expected 4
2 2 Expected 5
3 3 Expected 3
4 4 Expected 3
5 5 Expected 4
6 6 Expected 3
7 7 Expected 3
8 8 Expected 2
9 9 Expected 3
10 10 Expected 0
11 0 Truth 10
12 1 Truth 9
13 2 Truth 8
14 3 Truth 7
15 4 Truth 6
16 5 Truth 5
17 6 Truth 4
18 7 Truth 3
19 8 Truth 2
20 9 Truth 1
21 10 Truth 0

22 rows × 3 columns

In [5]:
%matplotlib inline
from ggplot import *
p = ggplot(aes(x='index'), data=data_lng) \
+ geom_area(mapping=aes(x="index", ymin="5%", ymax="95%", alpha=0.2), data=data, color="gray") \
+ geom_line(aes(x='index', y='value', linetype='variable'), data=data_lng) \
+ xlab("Day") + ylab("Estimate (days left)") + ggtitle("Effort estimate:\n90% confidence intervals")
p
Out[5]:
<ggplot: (288500165)>
In [6]:
ggsave("plot.png", p)
Saving 11.0 x 8.0 in image.

In [7]:
d2 = data[['5%', 'Expected', '95%', 'index']].copy()
d2['5%'] = data.ix[:, '5%'] - data.ix[:, 'Truth']
d2['95%'] = data.ix[:, '95%'] - data.ix[:, 'Truth']
d2['Expected'] = data.ix[:, 'Expected'] - data.ix[:, 'Truth']
d2
Out[7]:
5% Expected 95% index
0 -6 -5 15 0
1 -7 -5 6 1
2 -4 -3 10 2
3 -5 -4 7 3
4 -4 -3 7 4
5 -3 -1 9 5
6 -2 -1 10 6
7 -1 0 14 7
8 -1 0 8 8
9 0 2 9 9
10 0 0 0 10

11 rows × 4 columns

In [8]:
p2 = ggplot(aes(x='index'), data=d2)+ geom_hline(y=0, linestyle='dotted')\
+ geom_area(mapping=aes(ymin="5%", ymax="95%", alpha=0.2), color="gray") \
+ geom_line(aes(y='Expected'))  \
+ xlab("Day") + ylab("Estimate - True (days left)") \
+ ggtitle("Error in effort estimate:\n90% confidence intervals") \
+ ylim(-15, 15)
In [9]:
# For some reason, this shows two inline images
p2
Out[9]:
<ggplot: (289146017)>
In [10]:
ggsave("plot2.png", p2)
Saving 11.0 x 8.0 in image.

In [10]: