擅长:python、mysql、java
<p>打印前按x轴值排序。这是一个MWE。</p>
<pre><code>import itertools
x = [3, 5, 6, 1, 2]
y = [6, 7, 8, 9, 10]
lists = sorted(itertools.izip(*[x, y]))
new_x, new_y = list(itertools.izip(*lists))
# import operator
# new_x = map(operator.itemgetter(0), lists) # [1, 2, 3, 5, 6]
# new_y = map(operator.itemgetter(1), lists) # [9, 10, 6, 7, 8]
# Plot
import matplotlib.pylab as plt
plt.plot(new_x, new_y)
plt.show()
</code></pre>
<p>对于小数据,<a href="https://docs.python.org/2/library/functions.html#zip" rel="noreferrer">^{<cd1>}</a>(如其他回答者所述)就足够了。</p>
<pre><code>new_x, new_y = zip(*sorted(zip(x, y)))
</code></pre>
<hr/>
<p>结果是</p>
<p><a href="https://i.stack.imgur.com/ErrWx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ErrWx.png" alt="enter image description here"/></a></p>