Skip to content

Commit

Permalink
Add histogram plots; close pints-team/pints#783
Browse files Browse the repository at this point in the history
  • Loading branch information
chonlei committed May 7, 2019
1 parent 02b1388 commit 33c71a3
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions pfunk/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,73 @@
import pfunk


def histogram(results, variable, title, xlabel, threshold=None):
"""
Creates and returns a histogram plot for a variable (over commits).
"""
fig = plt.figure(figsize=(11, 4.5))
plt.suptitle(title + ' : ' + pfunk.date())

# Left plot: Variable per commit for all data as 1 histogram
plt.subplot(1, 2, 1)
plt.ylabel('Frequency')
plt.xlabel(xlabel)
fig.autofmt_xdate()
x, y, u, m, s = pfunk.gather_statistics_per_commit(results, variable)
if len(x) == 0:
plt.text(0.5, 0.5, 'No data')
else:
last_commit = [i for i, k in enumerate(x) if k == u[-1]]
y = np.asarray(y)
mask_lc = np.ones(y.shape, dtype=bool)
mask_lc[last_commit] = False

n, _, _ = plt.hist(y[mask_lc], bins='auto', color='#607c8e', alpha=0.7)

if len(last_commit) > 25:
plt.hist(y[last_commit], bins='auto', color='#0504aa', alpha=0.5,
label=u[-1])
else:
stem_height = [np.max(n)] * len(last_commit)
ml, sl, bl = plt.stem(y[last_commit], stem_height, label=u[-1])
plt.setp(ml, color='#0504aa', alpha=0.5)
plt.setp(sl, color='#0504aa', alpha=0.5)
plt.setp(bl, visible=False)


# Right plot: Same, to most recent data.
plt.subplot(1, 2, 2)
plt.ylabel('Frequency')
plt.xlabel(xlabel)
fig.autofmt_xdate()
x, y, u, m, s = pfunk.gather_statistics_per_commit(
results, variable, remove_outliers=False, n=12)
if len(x) == 0:
plt.text(0.5, 0.5, 'No data')
else:
last_commit = [i for i, k in enumerate(x) if k == u[-1]]
y = np.asarray(y)
mask_lc = np.ones(y.shape, dtype=bool)
mask_lc[last_commit] = False

n, _, _ = plt.hist(y[mask_lc], bins='auto', color='#607c8e', alpha=0.7)

if len(last_commit) > 10:
plt.hist(y[last_commit], bins='auto', color='#0504aa', alpha=0.5,
label=u[-1])
else:
stem_height = [np.max(n)] * len(last_commit)
ml, sl, bl = plt.stem(y[last_commit], stem_height, label=u[-1])
plt.setp(ml, color='#0504aa', alpha=0.5)
plt.setp(sl, color='#0504aa', alpha=0.5)
plt.setp(bl, visible=False)

plt.legend()

# raise NotImplementedError
return fig


def variable(results, variable, title, ylabel, threshold=None):
"""
Creates and returns a default plot for a variable vs commits.
Expand Down

0 comments on commit 33c71a3

Please sign in to comment.