From eb3955addfa05d7190495833c69fa009a2504ad8 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 3 Sep 2020 13:09:56 +0200 Subject: Plot heatmaps --- .arcconfig | 1 - data | 0 diffs.py | 69 +++++++++++++++++++++++++++----------------------------------- 3 files changed, 30 insertions(+), 40 deletions(-) delete mode 120000 .arcconfig create mode 100644 data diff --git a/.arcconfig b/.arcconfig deleted file mode 120000 index b947811..0000000 --- a/.arcconfig +++ /dev/null @@ -1 +0,0 @@ -../dill/.arcconfig \ No newline at end of file diff --git a/data b/data new file mode 100644 index 0000000..e69de29 diff --git a/diffs.py b/diffs.py index 8eb0088..3ca1f3a 100755 --- a/diffs.py +++ b/diffs.py @@ -3,15 +3,16 @@ from datetime import datetime from phabricator import Phabricator import numpy as np import matplotlib.pyplot as plt -import scipy.stats as st -from sklearn.datasets.samples_generator import make_blobs +import matplotlib.cm as cm +import matplotlib.dates as mdates +from scipy.ndimage.filters import gaussian_filter start = datetime(year=2020, month=7, day=1) def format_stamp(stamp): dt = datetime.utcfromtimestamp(stamp) - date = (dt - start).days + date = mdates.date2num(dt) time = dt.hour + dt.minute / 60.0 return [date, time] @@ -25,43 +26,33 @@ for d in diff: modified = format_stamp(int(d["dateModified"])) dates += [created, modified] -# Extract x and y -x = [i for i, j in dates] -y = [j for i, j in dates] -# Define the borders -xmin = 0 -xmax = 60 -ymin = 0 -ymax = 24 -print(xmin, xmax, ymin, ymax) -# Create meshgrid -xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j] - -positions = np.vstack([xx.ravel(), yy.ravel()]) -values = np.vstack([x, y]) -kernel = st.gaussian_kde(values) -f = np.reshape(kernel(positions).T, xx.shape) - -print(f) - -fig = plt.figure(figsize=(13, 7)) -ax = plt.axes(projection='3d') -surf = ax.plot_surface(xx, yy, f, rstride=1, cstride=1, cmap='coolwarm', edgecolor='none') -ax.set_xlabel('x') -ax.set_ylabel('y') -ax.set_zlabel('PDF') -ax.set_title('Surface plot of Gaussian 2D KDE') -fig.colorbar(surf, shrink=0.5, aspect=5) # add color bar indicating the PDF -ax.view_init(90, -90) -plt.show() -#h =plt.hist2d(x, y) -#plt.colorbar(h[3]) -#plt.show() +def myplot(x, y, s, bins=1000): + heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins) + heatmap = gaussian_filter(heatmap, sigma=s) + + extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] + return heatmap.T, extent + +fig, axs = plt.subplots(2, 2) -#plt.scatter(X[:, 0], X[:, 1], s=50, c = truth) -#plt.title(f"Example of a mixture of {n_components} distributions") -#plt.xlabel("x") -#plt.ylabel("y"); + +sigmas = [0, 16, 32, 48] +x = [i for i, j in dates] +y = [j for i, j in dates] +daymonthFmt = mdates.DateFormatter('%d %B') + +for ax, s in zip(axs.flatten(), sigmas): + ax.xaxis.set_major_formatter(daymonthFmt) + _ = plt.xticks(rotation=90) + if s == 0: + ax.plot(x, y, 'k.', markersize=5) + ax.set_title("Scatter plot") + else: + img, extent = myplot(x, y, s) + ax.imshow(img, extent=extent, origin='lower', cmap=cm.jet) + ax.set_title("Smoothing with $\sigma$ = %d" % s) + +plt.show() -- cgit v1.2.3-54-g00ecf