Skip to content

Instantly share code, notes, and snippets.

@barrysmyth
barrysmyth / plot_heatline_with_border.py
Last active November 21, 2023 16:33
plot_heat_line_with_border.py
def plot_heatline_with_border(ax, x, y, c, w, bw=4, bc='midnightblue'):
"""Plot a colour-coded segmented line graph with a border.
Args:
ax - the current axis.
x - x-axis values.
y - y-axis values.
c - the colours for the segments in the line graph defined by x, y.
w - the line widths for the segments in the line graph defined by x, y.
bw - the border thisckness.
bc - the border colour.
def plot_heatline(ax, x, y, c, w):
"""Plot a colour-coded segmented line graph with a border.
Args:
ax - the current axis.
x - x-axis values.
y - y-axis values.
c - the colours for the segments in the line graph defined by x, y.
w - the line widths for the segments in the line graph defined by x, y.
"""
def plot_session_pie(headline, header, chart, footer, session, fontsize=15, min_frac=0.05):
""" Plot a pie chart based on the minutes in each HR zone for the session.
Args:
headline - axis for the chart headline/title
header - axis for the chart header info (weekly mins, RE, % easy).
chart - axis for the main chart (horizontal bar).
footer - axis for the weekly kms and mean pace.
week - a dataframe with data for the week to be summarised.
def plot_training_week_summary_bars(headline, header, chart, footer, week, fontsize=15):
""" Plot a summary of the training week.
Args:
headline - axis for the chart headline/title.
header - axis for the chart header info (weekly mins, RE, % easy).
chart - axis for the main chart (horizontal bar).
footer - axis for the weekly kms and mean pace.
week - a dataframe with data for the week to be summarised.
@barrysmyth
barrysmyth / training_log_grid_detailed.py
Last active November 12, 2023 16:31
training_log_grid_16_x_8.py
# The unit height of each row.
row_h = 10
# The outer grid.
sessions_grid = gridspec.GridSpec((16*row_h), 8, figure=fig, wspace=.1, hspace=.5)
fig = plt.figure(figsize=(10, 20))
# Iterate for each row (16 weeks) and column (weekly summary col + 7 x days) ...
for row in range(16):
from matplotlib.pylab import plt
# Create a 16x8 grid of axes.
fig, axs = plt.subplots(figsize=(4, 10), nrows=16, ncols=8)
# Assign plots to asxes ...
plot_weekly_summary(ax=axs[0, 0], ...)
plot_session_pie(ax=axs[0, 1], ...)
:
@barrysmyth
barrysmyth / wordle_simulator_outline.py
Last active May 9, 2022 19:11
A outline Wordle simulator.
def play_wordle(target, words, v):
"""
Play Wordle for a given target word.
Args:
target: the target word.
words: the words available as guesses.
v: the vocabulary setting.
@barrysmyth
barrysmyth / collatz_harriss_adjusted.py
Last active April 18, 2022 09:51
A modified Edmund Harriss type plot of a Collatz orbit.
import math
import numpy as np
import matplotlib.pylab as plt
def harriss_plot_adj(
ax, n,
angle=11.45, twist=1.8, # Controls the odd/even turn angles
@barrysmyth
barrysmyth / collatz.py
Created April 18, 2022 09:14
Creating Collatz sequences/orbits from an integer.
def collatz(n):
"""The Collatz operator: If n is even return n/2 else return 3n+1."""
# If n is even then divide by 2.
if n%2==0:
return int(n/2)
# Otherwise return 3n+1
else:
return (3*n)+1
@barrysmyth
barrysmyth / collatz_harriss.py
Last active April 18, 2022 09:51
The Edmund Harriss visualisation of a Collatz orbit.
import math
import numpy as np
import matplotlib.pylab as plt
def turn_angle(n, angle, twist):
"""Compute the turn angle based on whether n is even or odd.
Args: