matplotlib在python中绘制问题,以显示在每个状态上花费的时间 恐怕我有两条路,第0和第1州。 让我们考虑一下,当我遵循一个路径状态:0花费了一定的时间在0和一定的时间在1。br>

matplotlib在python中绘制问题,以显示在每个状态上花费的时间 恐怕我有两条路,第0和第1州。 让我们考虑一下,当我遵循一个路径状态:0花费了一定的时间在0和一定的时间在1。br>,python,matplotlib,graph,Python,Matplotlib,Graph,比如, State Time spend on each state 0 1.099190425147403394e+00 1 2.109956038727701433e+00 0 4.392933181897487049e-01 1 1.026012186825693284e+00 0 1.339228438495629003e+00 1 1.327323517945566023e+00

比如,

State    Time spend on each state 
  0      1.099190425147403394e+00 
  1      2.109956038727701433e+00 
  0      4.392933181897487049e-01 
  1      1.026012186825693284e+00 
  0      1.339228438495629003e+00 
  1      1.327323517945566023e+00 
当我沿着一条路径走时,状态0和1交替出现(如第1列),y轴和x轴将是显示每个状态花费时间的时间(水平直线的宽度将表示每个状态花费的时间),我如何绘制一个图来显示这一点如下图所示,使用python matplotlib, 州政府花费一定的时间

尝试:

plt.step(df['Time spend on each state'].cumsum().shift(fill_value=0), 
     df['State'], where='post')
输出:


谢谢你的回答。这两个数据的状态和在每个状态上花费的时间在两个不同的文件中。有没有一种方法可以使用两个不同的文件进行打印data@IndraniChoudhuri答案直指你的问题。接受它是正确的感谢方式。进一步的问题可以作为新问题发布。