I've got a set of datetime data in a pandas series of the format 2020-10-02 18:48:21
. I want to plot only the time contained within that datetime against a score value in another DataFrame.
Below is the closest that I've gotten using the following code:
def timePop(oneDate, oneScore, twoDate, twoScore, title):
myFmt = "%H:%M:%S"
for index, value in oneDate.iteritems():
new_time = datetime.fromtimestamp(oneDate[index]).time()
oneDate[index] = datetime.strptime(str(new_time), myFmt)
for index, value in twoDate.iteritems():
new_time2 = datetime.fromtimestamp(twoDate[index]).time()
twoDate[index] = datetime.strptime(str(new_time2), myFmt)
fig, ax = pylt.subplots()
ax.scatter(oneDate, oneScore, c='r', marker='*', label="Popular")
ax.scatter(twoDate, twoScore, c='b', marker='o', label="Unpopular")
pylt.xlabel('24 Hours')
pylt.ylabel('Scores')
pylt.xticks(rotation=45)
# ax.format_xdata = mdates.DateFormatter(myFmt)
# ax.set_xticks([0, 1, 2, 3, 4, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24])
pylt.title('Time and Score Distribution of Posts in %s' % title)
pylt.show()
I've worked through a variety of the possible solutions here on StackOverflow, as well as through the docs, but no luck. Ideally, I'd like the x-axis to go in increments of 1 hr. If anyone can help, I'd appreciate it.