0

目前,这些点正在按照它们进入图表的顺序进行连接。有没有办法从 x 坐标从左到右排序?

plt.errorbar(xvals, yvals, yerr=errors, linestyle='-', color='orange')

在此处输入图像描述

4

1 回答 1

1

由于您已经安装了 matplotlib,因此您已经安装了 numpy,并且您可以使用 numpy按 x-order 对 x 和 y 进行排序

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 8, .1)
np.random.shuffle(x)
y = np.sin(x)

sx = np.argsort(x)  # find the order for sorting x
x2 = x[sx]          #    apply this to x
y2 = y[sx]          #    apply this to y

plt.plot(x, y, 'y')
plt.plot(x2, y2, 'r', linewidth=4)

plt.show()

在此处输入图像描述

于 2013-10-15T02:23:06.013 回答