Any explication why I got this kind of plot? The range of index returns is from 100 to 130. I need help to understand this plot above. The code is simple, but the plot
Matplotlib plots the data in the order it is provided. You may sort the data if that is required.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([3, 5, 1, 2, 7, 4, 6, 9, 8])
y = np.array([8, 10, 3, 6, 8, 10, 10, 3, 6])
plt.subplot(121)
plt.plot(x,y, marker="o", label="unsorted")
plt.legend()
# now sort the values
plt.subplot(122)
plt.plot(np.sort(x),y[np.argsort(x)], marker="o", color="C3", label="sorted")
plt.legend()
plt.show()