I am plotting my workout weights against "Date Weekday". I want to connect all the points which match the condition:
weights = ([1471.5, 4026. , 2399.5, 5462. , 0. , 2758.1, 6229. , 5132. ])
dates = ['16 Thu', '20 Mon', '21 Tue', '22 Wed', '23 Thu', '24 Fri','25 Sat','27 Mon']
any(x in dates[i] for x in ["Mon","Thu"])
I saw this question Plotting lines connecting points But this addresses every two points but my problem is that I might skip some days. I want the code to be robust.
I was using this for the above "dates" and "weights":
plt.pyplot.plot(dates,weights,'ro-')
plt.pyplot.xticks(dates)
plt.pyplot.grid(b=True, which='major', color='#666666', linestyle='-')
plt.pyplot.yticks(weights)
plt.pyplot.show()
Which produced this disconnected plot:
I want this output:
So I did this:
MonThudate = []
TueFridate = []
WedSatdate = []
MonThuwt = []
TueFriwt = []
WedSatwt = []
for i in range(len(dates)):
if any(x in dates[i] for x in ["Mon","Thu"]):
MonThudate.append(dates[i])
MonThuwt.append(weights[i])
if any(x in dates[i] for x in ["Tue","Fri"]):
TueFridate.append(dates[i])
TueFriwt.append(weights[i])
if any(x in dates[i] for x in ["Wed","Sat"]):
WedSatdate.append(dates[i])
WedSatwt.append(weights[i])
#MonThuDate = ['16 Thu', '20 Mon', '23 Thu', '27 Mon']
#MonThuwt = [1471.5, 4026.0, 0.0, 5132.0]
plt.pyplot.plot(MonThudate,MonThuwt,'ro-')
plt.pyplot.plot(WedSatdate,WedSatwt,'ro-')
plt.pyplot.plot(TueFridate,TueFriwt,'ro-')
It produced this:
But here, the x-axis is not the same for the whole graph. It is disjoint.