Mar-23-2022, 01:26 PM
(This post was last modified: Mar-23-2022, 03:13 PM by Yoriz.
Edit Reason: removed unnecessary quote of previous post
)
Done with the Fri_2017 list, x-axis labels are periodic but asymmetric as the 22nd and 1st are close together followed by a longer space and then another 22nd and 1st, etc. Is this "evenly sized intervals appropriate for the plot?" I would have thought if left to auto scale, matplotlib would have selected intervals that were really evenly spaced out (e.g. every Z x-value increments and since an x-value here is one week, that translates to every Z weeks).
Incidentally, last time I posted a question about matplotlib I didn't get a response and I figured that might have been because the code was too long and messy for people to bother wading through.
Sorry you had to take the time to reconstruct everything, Dean. My code here went something like this:
Incidentally, last time I posted a question about matplotlib I didn't get a response and I figured that might have been because the code was too long and messy for people to bother wading through.
Sorry you had to take the time to reconstruct everything, Dean. My code here went something like this:
from datetime import datetime from datetime import timedelta import random import numpy as np import matplotlib.pyplot as plt Fri_2017 = [] #2017_Fri gives "invalid decimal literal" at the underscore random_pnl_list = [] cumul_pnl_from_random = [] start_date = datetime(2017,1,1) #not datetime.datetime() while True: #True must be capitalized if start_date.weekday() == 4: Fri_2017.append(start_date) break else: start_date += timedelta(days=1) for i in range(19): Fri_2017.append(Fri_2017[-1] + timedelta(days=7)) converted_Fri_2017 = [d.strftime('%Y-%m-%d') for d in Fri_2017] #list comprehension print(converted_Fri_2017) for i in range(20): random_pnl_list.append(random.randint(-1000,1000)) cumul_pnl_from_random = list(np.cumsum(random_pnl_list)) #np returns array but this MUCH easier than doing loop to compute print(random_pnl_list) print(cumul_pnl_from_random) fig, [ax1, ax2] = plt.subplots(2) plt.sca(ax1) plt.plot(Fri_2017,cumul_pnl_from_random) plt.xticks(rotation=90) plt.sca(ax2) plt.plot(converted_Fri_2017,cumul_pnl_from_random) plt.xticks(rotation=90) plt.tight_layout() plt.show()