How to plot multiple plots separately?

Viewed 134

X Dataset:

x = [1.02, .95, .87, .77, .67, .56, .44, .30,
.16, .01, 1.02, .95, .87, .77, .67, .56, .44,
.30, .16, .01, 1.02, .95, .87, .77, .67, .56,
.44, .30, .16, .01, ...................]

Y Dataset:

y = [0.39, .32, .27, .22, .18, .15, .13, .12,
.13, .15, 0.56, .37, .67, .27, .15, .13, .12,
.09, .06, .03,....................................]

I have this kind of data where x is repeating after 10 values and y is changing accordingly. I want to plot this data in one graph. I tried this:

plt.plot(x, y)
plt.show()

and get the following plot: enter image description here

But in this graph, the last point of one graph is connected to the first point of the next graph. I want to separate them. I want to plot like this:

enter image description here

1 Answers

You can iterate through the x values by 10's, and then use slicing to plot each x repeat accordingly.

for i in range(1, len(x) // 10 + 1):
    plt.plot(x[(i - 1) * 10:i * 10], y[(i - 1) * 10:i * 10])
plt.show()
Related