【问题标题】:Specify join order in matplotlib在 matplotlib 中指定连接顺序
【发布时间】:2013-10-15 10:23:06
【问题描述】:

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

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

【问题讨论】:

标签: python matplotlib


【解决方案1】:

因为你已经安装了 matplotlib,所以你已经安装了 numpy,你可以使用 numpy 按 x 顺序对 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()

【讨论】:

    猜你喜欢
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 2021-11-08
    • 1970-01-01
    • 2017-05-10
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多