python27 matplotlib: first and last element connected

前端 未结 5 1697
野趣味
野趣味 2020-12-17 00:08

Hi I have found the same problem but without an answer: enter link description here

My problem is that I try to plot data with the matplotlib and it connects the fir

5条回答
  •  一生所求
    2020-12-17 00:56

    Good question! Had a similar problem while plotting time stamped data from a circular buffer. The other answers explained what was going on.

    The plot is processing the vectors in strict order, drawing a line from first coordinate to second and so on. But a circular buffer can start with lowest time at any point.

    Thus the plot will often start somewhere in the middle of the plot window with nice incrementing time. Then it reaches the insertion point and jumps back in time to the start of the window -- drawing an ugly line -- then resuming up to the starting point.

    The quick solution was replacing this line:

    plot(pTime, pPos)
    

    with two lines plotting each half in the right order:

    plot(pTime[ptr:], pPos[ptr:])
    plot(pTime[0:ptr], pPos[0:ptr])
    

提交回复
热议问题