Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active March 6, 2025 05:51
Show Gist options
  • Save patwooky/a44a3ac5e86833e198d667cf36323829 to your computer and use it in GitHub Desktop.
Save patwooky/a44a3ac5e86833e198d667cf36323829 to your computer and use it in GitHub Desktop.
One Percent Every Day
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# One Percent Improvement Every Day\n",
"\n",
"### I came across the above phrase, and wondered:\n",
"\n",
"Given a very small starting number, and incrementing it by 1% a day, how many days does it take to get to the 100% mark?\n",
"\n",
"I am setting out to create a chart that maps the increase.\n",
"\n",
"For more information on this concept see: [Marginal gains philosophy](https://en.wikipedia.org/wiki/Dave_Brailsford?wprov=srpw1_0#'Marginal_gains'_philosophy)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Python 3.11"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"def plot_percentages(percent_start, figsize=(10, 8)):\n",
" countBreak = 0\n",
" # percent_start = 0.01 # starting out with 2 decimal places (or 1-e2)\n",
" percent = percent_start\n",
" percentList = []\n",
" maxCountBreak = 1000000\n",
" while(percent <= 100.0 and countBreak <= 1000000):\n",
" countBreak += 1\n",
" # increment percent by 1%\n",
" percent *= 1.01\n",
" percentList.append(percent)\n",
" # print(f'{countBreak}: {percent:.8f}')\n",
" # print(f'{countBreak} days have passed')\n",
" # print(f'This is equivalent to {countBreak//365:.0f} years and {countBreak%365} days')\n",
"\n",
" # Normalize percentList to the range 0 to 1\n",
" # max(percentList) gives the maximum value in percentList\n",
" percentListNormalized = [x / max(percentList) for x in percentList]\n",
"\n",
" # Create a list of days from 0 to 1\n",
" daysNormalised = [x / len(percentList) for x in range(len(percentList))]\n",
"\n",
" # Create a list of normalised years from 0 to len()/365\n",
" maxYears = (len(percentList)//365)\n",
" if len(percentList) % 365 > 0:\n",
" # +1 because we want to include the last year\n",
" maxYears += 1\n",
" yearsNormalised = [x / maxYears for x in range(maxYears)]\n",
"\n",
" # Create a figure with a specific background color\n",
" fig, ax = plt.subplots(figsize=figsize)\n",
" fig.patch.set_facecolor('lightgray') # Set figure background color\n",
" ax.set_facecolor('whitesmoke') # Set axes background color\n",
"\n",
" # Plot the line\n",
" ax.plot(daysNormalised, percentListNormalized, linestyle='-', color='cyan', linewidth=0.52)\n",
"\n",
" # Plot the markers\n",
" ax.plot(daysNormalised, percentListNormalized, marker='+', linestyle='', color=(.5, 0.2, 0.1), markersize=2.5, linewidth=0.52)\n",
"\n",
" # Add titles and labels\n",
" ax.set_title(f'Percentage Values Over {len(percentList)} Days ({len(percentList) / 365:.2f} Years) Starting from {percent_start}%', \n",
" fontsize=14)\n",
" ax.set_xlabel('Day of the Year', fontsize=11)\n",
" ax.set_ylabel('Percentage Value', fontsize=11)\n",
"\n",
" # Set custom x-axis tick labels\n",
" num_ticks = 10 # Number of ticks you want on the x-axis\n",
" ticks = [i / num_ticks for i in range(num_ticks + 1)]\n",
" tick_labels = [f'{tick:.1f}\\n({(tick * len(percentList)) / 365:.2f}yr)' for tick in ticks]\n",
" ax.set_xticks(ticks)\n",
" ax.set_xticklabels(tick_labels, rotation=0, ha='right', fontsize=8)\n",
"\n",
" # Set custom y-axis tick labels manually\n",
" y_ticks = [i / num_ticks for i in range(num_ticks + 1)]\n",
" y_tick_labels = [f'{tick * 100:.0f}%' for tick in y_ticks]\n",
" ax.set_yticks(y_ticks)\n",
" ax.set_yticklabels(y_tick_labels, fontsize=8)\n",
"\n",
" # Set grid color\n",
" ax.grid(True, color='gray', linestyle='--', linewidth=0.5)\n",
"\n",
" # Create a secondary x-axis\n",
" secax = ax.twiny()\n",
"\n",
" # Set the same x-axis limits\n",
" secax.set_xlim(ax.get_xlim())\n",
"\n",
" # Set secondary x-axis tick labels\n",
" sec_ticks = [i / maxYears for i in range(len(yearsNormalised))]\n",
" sec_tick_labels = [f'Year {id:.0f}' for id, tick in enumerate(sec_ticks)]\n",
" secax.set_xticks(sec_ticks)\n",
" secax.set_xticklabels(sec_tick_labels, color='darkred', fontsize=10) # Custom text color and font size\n",
"\n",
" # Show the plot\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_percentages(.0001, (12,8))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_percentages(.001, (12,8))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_percentages(.01, (12,8))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_percentages(.1, (12,8))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_percentages(1, (12,8))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

One Percent Improvement Every Day

python 3.11

I came across the above phrase

Given a very small starting number, and incrementing it by 1% how many days does it take to get to the 100% mark? I am setting out to create an increment chart.

For more information on this concept see: Marginal gains philosophy

From the code, I generated 5 graphs, each with different starting values from 0.0001% to 1%.

Here are the charts in ascending order of starting values.

Increment Chart

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment