title: Scatterplot in Matplotlib with its natural line
body: <p>While joining the points given by scatterplot in matplotlib, I only want to get the natural fit, and not x-y , which becomes a zig-zag as shown below. </p>
  
  <p>How can I do this in matpotlib ? </p>
  
  <p>PS: I don't want fitting polynomial/regression line, just the regular natural line</p>
  
  <pre><code>from pylab import *
  import matplotlib.pyplot as plt
  
  //Generate some x-y data for yourself...
  x=[key for key in my_dict.keys()]
  y=[imp for imp in my_dict.values()]
  xlim([min(x),max(x)])
  ylim([min(y),max(y)])
  plt.scatter(x,y)
  </code></pre>
  
  <p>I get :</p>
  
  <p><img src="https://i.stack.imgur.com/WBQh5.png" alt="enter image description here"></p>
  
  <p>On doing basic plot along with this, I get connected, but overlapping lines</p>
  
  <pre><code>plt.plot(x, y, '-o')
  plt.show()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/LUaUA.png" alt="enter image description here"></p>
  
  <p>What I would like to have:</p>
  
  <p><img src="https://i.stack.imgur.com/jQWvk.png" alt="enter image description here"></p>
  
  <p>Related <a href="https://stackoverflow.com/questions/6328138/scatterplot-instead-of-a-lineplot-while-using-the-plotfile-function-of-matplotlib">q/a</a> but doesn't exactly fit my case</p>
  
  <p>Fallback Alternatives  - Fit a n-th degrees polynomial as here -
  <a href="https://stackoverflow.com/questions/11856206/multivariate-polynomial-best-fit-curve-in-python">Multivariate (polynomial) best fit curve in python?</a></p>
  
  <p><strong>Edit :</strong>- I tried the code below as suggested </p>
  
  <pre><code>[x, y] = zip(*sorted(zip(x, y), key=lambda x: x[0])) ###
  plt.plot(x, y, '-o') 
  </code></pre>
  
  <p>here's what I now get, butI am looking for something more smoother.</p>
  
  <p><img src="https://i.stack.imgur.com/VW6qh.png" alt="enter image description here"></p>