1

I have data like this:

X = array([ 24.41,  54.98,  89.57, 114.26, 133.61, 202.14, 250.99, 321.31,
       333.47, 373.79, 422.02, 447.41, 522.47, 549.53,  20.15,  39.12,
        73.42, 134.03, 179.86, 262.52, 337.23, 432.68, 253.24, 346.62,
       450.1 , 552.22, 656.2 ,  33.84,  60.41,  94.88, 147.73, 206.76,
       237.12, 372.72, 495.47, 544.47,  28.93,  49.87,  85.15, 143.84,
       226.86, 339.15, 393.32, 524.7 , 623.86,  39.22,  96.44, 156.92,
       223.88, 271.78, 349.52, 429.66, 523.03, 622.05, 748.29, 646.89,
       749.27, 851.37, 851.61])
y = array([ 0.70168044,  4.93931985,  8.71831269, 10.84590729, 12.22458808,
       15.46380214, 16.61898425, 17.29600649, 17.34369784, 17.43434118,
       17.50907445, 17.57419685, 18.00322011, 18.26260499,  0.03686716,
        2.85433237,  7.0779359 , 12.25192523, 14.65463193, 16.79352551,
       17.35594282, 17.53284075, 16.65553712, 17.38224061, 17.58297862,
       18.29143563, 19.71214346,  2.10666383,  5.59990814,  9.21325511,
       13.08716841, 15.60686344, 16.36464679, 17.43271999, 17.80134835,
       18.20983513,  1.38643181,  4.29326544,  8.28990266, 12.86092195,
       16.1416266 , 17.36179504, 17.46194981, 18.02244612, 19.22640164,
        2.86822848,  9.35464796, 13.58885705, 16.07082828, 16.91213557,
       17.38928103, 17.52563605, 18.00801144, 19.19976288, 20.8797045 ,
       19.5713721 , 20.88735117, 20.40458438, 20.39937509])

When I plot them using:

import matplotlib.pyplot as plt
plt.plot(X, y, "ro", markersize=6)
plt.plot(X, y)

I get:

![]

My expectation would be one line that connects from red point to red point, but no matter how I tweak the parameters a subset of points get connected by straight lines. I am reading through the documentation and can't figure out what parameters to tweak to stop these lines from appearing.

0

1 Answer 1

1

Sort your data before doing the line plotting:

index =np.argsort(X)
plt.plot(X, y, "ro", markersize=6)
plt.plot(X[index], y[index])
plt.show()

If you don't do this, the lines will be drawn in the order you have in your data - as you see in your plot.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was straightforward enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.