I want to show how much time a user spends on few tasks in a day using horizontal bar chart. y-axis is list of tasks and x-axis is time spent on those tasks. The time is in %H:%M:%S format.
fig, ax = plt.subplots()
# Example data
tasks = ('Reading', 'Mobile', 'Outing', 'Laptop')
y_pos = np.arange(len(tasks))
time_spent = ["01:01:34","00:05:23","00:00:09","02:34:32"]
error = np.random.rand(len(tasks))
ax.barh(y_pos, time_spent, xerr=error, align='center')
ax.set_yticks(y_pos)
ax.set_yticklabels(tasks)
ax.set_xlabel('Time spent')
ax.xaxis.set_major_locator(HourLocator())
ax.xaxis.set_major_formatter(DateFormatter('%H:%M:%S'))
plt.show()
I found this somewhere and it's not working. I am not even able to tweak it to get worked. Please suggest the solution. Additionally, I also want to show the time spent after each horizontal bar. Any ideas for that are also appreciable.