Skip to content

Instantly share code, notes, and snippets.

@hartwork
Created June 8, 2024 16:15
Show Gist options
  • Save hartwork/9e7593e25664477efa4c06fd38203f78 to your computer and use it in GitHub Desktop.
Save hartwork/9e7593e25664477efa4c06fd38203f78 to your computer and use it in GitHub Desktop.
Plot 1% loss/gain per day for one year
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license
import math
import pylab
from matplotlib import pyplot
START = 100
DAYS = 365
LOSS = [START * 0.99 ** i for i in range(DAYS)]
GAIN = [START * 1.01 ** i for i in range(DAYS)]
fig = pyplot.figure()
SUBPLOT_ROWS = 2
SUBPLOT_COLS = 1
for subplot_index, (yscale, ylim) in enumerate((
('linear', [0, 500]),
('log', [0, 10 ** math.ceil(math.log10(GAIN[-1]))]),
)):
sub_plot = fig.add_subplot(SUBPLOT_ROWS, SUBPLOT_COLS, subplot_index + 1)
sub_plot.title.set_text(f'{yscale} Y scale')
sub_plot.set_yscale(yscale)
sub_plot.set_xlim([0, DAYS])
sub_plot.set_ylim(ylim)
sub_plot.plot(LOSS, color='red')
sub_plot.plot(GAIN, color='blue')
fig.subplots_adjust(hspace=0.3) # stop second title from overlapping
pylab.show()
@hartwork
Copy link
Author

hartwork commented Jun 8, 2024

Screenshot_20240608_181727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment