Python matplotlib draws a line chart, the first time it is normal, the second time it will be connected from beginning to end, ask for advice to solve?

when using matplotlib to draw a line chart, it is normal to draw it the first time, but the second time it is connected from beginning to end.



Aug.31,2021

Please check the data to see if there is such a situation as [1 hr class= 2 answer 3 4 5 1], that is, from the origin to the origin.
in addition to the supply code, how can people judge the problem?


the problem has been solved. If a small partner has this kind of problem. You can check whether the source data is incorrect. Because I have a lot of code and miscellaneous, so I didn't post it. For example, the data used for the first drawing is x = [1, 2, 3, 4, 5, 6], y = [10, 12, 13, 11, 10, 13]; Later, I need to redraw the graph. Although I use the cla () method and query the new data x = [7, 8, 9, 10], y = [9, 11, 10, 8] and then draw the graph, because the x and y data in my code are stored with the class attributes of the object, I did not empty the original data. The data of the second drawing becomes: X = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y = [10, 12, 13, 11, 10, 13, 9, 11, 10, 8]. As a result, the above results are produced. Not only that, but the axes also produce strange changes. I was convinced myself.

Menu