Often the data is taken in an arbitrary order. If you try to plot such data connected with lines, you would get a messy plot like shown below.
A better strategy is to presort the data. As shown in the script below.
import matplotlib.pyplot as plt
import numpy as np
=np.array([0, 5, 2, 1, 6])
x=np.array([0, 25, 4, 1, 36])
y
# Often data is taken in arbitrary order, but it makes ugly plots
# since the points are plotted and joined in the order of appearance
'o-')
plt.plot(x,y, 'Unsorted data connected with lines')
plt.title('unsorted_plot.svg')
plt.savefig(
# A better way to have index which list data in a sorted way
=np.argsort(x)
ind# now we plot according to the sort order
plt.clf()'o-')
plt.plot(x[ind], y[ind], 'Sorted data connected with lines')
plt.title(
'sorted_plot.svg') plt.savefig(