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
I had the same problem. The solution I found was in the .txt file where my data was stored. The data set existed twice in the file and therefor caused the connection of start and endpoint by matplotlib.
Removing double data and the graph plotted properly. Fortunately, the two datasets appeared one after the other. So it was easy to delete the first part.
Since it was a huge data collection in my case, this was not obvious and therefor took some time to realise.
The problem was caused in creating the txt-file....
So all correct with matplotlib.
Cheers, Rick
I just had the same problem.
In my case I was dealing with 365 days of the year. The indexing starts from 0 and ends at 365 while the day numbers start from 1 and end at 366 so the date corresponding to the 366th line was 1 and that's why there was a line connecting the end of plot to its beginning. I also needed to check for leap years because the data was collected from a period of 10 years.
Pyplot is connecting the first (x,y) point with the second (x,y) point, with the third and so on... so it looks like there may be a (duplicate?) low value hidden towards the end of your x
.
You can try x == sorted(x)
to double check if your list is strictly ascending. It will return False
if it's not.
You will probably want to find the (x,y) pair before you call your plot()
function, so I'll leave that to you for now.
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])
I had similar problem as you can see:
BEFORE
I just sorted x
using this:
x = sorted(x)
And the line disappeared as you can see: (But the data is disturbed due to sorting).
AFTER SORTING
You must also make sure the respective y
values should also be accordingly arranged for the sorted x
. The final output is here:
FIXED