1

I need help with understanding the answer to this questions asked previously here on stackoverflow:

Pandas - Stacked horizontal barchat for timeline?

The question was about using a stacked horizontal bar-chart as a timeline. The answer given works but there isn't the possibility to see the dataframe from which the graph is generated and this is where I'm getting stuck. I would like to do something similar to this but since I can't see the df I don't really know how to replicate it.

I want to track the different states of bodies over-time on a timeline such as that one.

Anyone know how this would work?

This was the code given in the answer:

fig, ax = plt.subplots()
df.plot(kind='barh', stacked=True, ax=ax)
ax.set_yticklabels(['A', 'B', 'C', 'D', 'E', 'F'])
time = pd.date_range(start=pd.to_datetime('07:00', format='%H:%M'), end=pd.to_datetime('13:00', format='%H:%M'),freq='H')
time_x = [dt.strftime('%H:%M') for dt in time]
ax.set_xticklabels(time_x)
fig.autofmt_xdate()
plt.show()
  • The dataframe used is something along the lines of `df= pd.DataFrame(np.random.rand(6,4), columns=list("abcd"))`. The answer itself has a flaw. It sets the labels, but not the tickpositions. You are right that in total this is not very useful, so why don't you make it better and provide a [mcve] yourself and ask for the problem you encounter? – ImportanceOfBeingErnest Apr 08 '19 at 15:39

0 Answers0