你好,pandas数据进行sort,你只需要对x进行sort,y不需要的
import pandas as pd
from matplotlib import pyplot as plt
d = {'x': [3, -1, 2, -2, 5], 'y': [2, 5, 2, 4, 3]}
df = pd.DataFrame(data=d)
plt.figure(1)
plt.plot(d['x'], d['y'],'r--')
df = df.sort_values(by='x', ascending=True)
plt.plot(df['x'], df['y'],'b-.')
plt.legend(['before sort','after sort'])
plt.show()