summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2020-09-03 14:45:10 +0200
committerDennis Kobert <dennis@kobert.dev>2020-09-03 14:45:10 +0200
commit44de73a29f24777197c1d87e4afa29bcffd44afa (patch)
tree979dbc903aae2d4a313e9d0deb3e9a66d8f3ba3a
parentc001f0d080ca2d2b152b83773779b8138aa0d17a (diff)
Plot both graphs on the same plotHEADmaster
-rwxr-xr-xdiffs.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/diffs.py b/diffs.py
index a866e12..c9e7830 100755
--- a/diffs.py
+++ b/diffs.py
@@ -7,15 +7,18 @@ import matplotlib.cm as cm
import matplotlib.dates as mdates
import matplotlib.ticker as tick
from scipy.ndimage.filters import gaussian_filter
+import pandas as pd
start = datetime(year=2020, month=7, day=1)
width = 6
+xoff = 2
+yoff = 2
def format_stamp(stamp):
dt = datetime.utcfromtimestamp(stamp)
- date = (dt.weekday() + 5) % 7 * width
- time = dt.hour + dt.minute / 60.0
+ date = dt
+ time = (dt.hour + 24 - yoff) % 24 + dt.minute / 60.0
return [date, time]
@@ -30,12 +33,12 @@ for d in diff:
def y_fmt(x, y):
- return f"{int(x//1)}:{int(x%1 * 60)}"
+ return f"{(int(x//1 + yoff))%24}:{int(x%1 * 60)}0"
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
def x_fmt(x, y):
- return weekDays[int((x/width + 2) % 7)]
+ return weekDays[int((x/width + xoff) % 7)]
def myplot(x, y, s, bins=1000):
heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
@@ -48,23 +51,34 @@ def myplot(x, y, s, bins=1000):
fig, axs = plt.subplots(2, 2)
-sigmas = [0, 16, 32, 48]
-x = [i for i, j in dates]
+sigmas = [0, 0, 32, 32]
+x = [mdates.date2num(i) for i, j in dates]
+x2 = [(dt.weekday() + 7 - xoff) % 7 * width for dt, 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)
+for i, ax, s in zip(range(len(x)), axs.flatten(), sigmas):
+ px = x
+ if i % 2 == 0:
+ ax.xaxis.set_major_formatter(tick.FuncFormatter(x_fmt))
+ ax.xaxis.set_ticks(np.arange(0, 7 * width, width))
+ px = x2
+ ax.set_title( "Commits per weekday")
+ else:
+ ax.xaxis.set_major_formatter(daymonthFmt)
+ ax.set_title( "Commits per day")
+ #ax.xaxis.set_ticks(pd.date_range(start="2020-07", end="2020-09", freq="D"))
+ #ax.tick_params(labelrotation=90)
+
ax.yaxis.set_major_formatter(tick.FuncFormatter(y_fmt))
- ax.xaxis.set_major_formatter(tick.FuncFormatter(x_fmt))
- ax.xaxis.set_ticks(np.arange(0, 7 * width, width))
+ ax.yaxis.set_ticks(np.arange(0, 25, 1.0))
+ ax.ylabel = "Time"
if s == 0:
- ax.plot(x, y, 'k.', markersize=5)
- ax.set_title("Scatter plot")
+ ax.plot(px, y, 'k.', markersize=5)
+ ax.set_title( ax.get_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)
+ img, extent = myplot(px, y, s)
+ ax.imshow(img, extent=extent, origin='lower', cmap=cm.magma)
+ ax.set_title( ax.get_title() + " Smoothing with $\sigma$ = %d" % s)
plt.show()