更新时间:2023-11-09 20:10:46
我不认为你可以在 plot
中使用颜色数组(文档说颜色可以是任何 matlab 颜色,而 scatter
文档说您可以使用数组).
I don't think that you can use an array of colors in plot
(the documentation says that color can be any matlab color, while the scatter
docs say you can use an array).
但是,您可以通过单独绘制每一行来伪造它:
However, you could fake it by plotting each line separately:
import numpy
from matplotlib import pyplot as plt
x = range(10)
y = numpy.random.choice(10,10)
for x1, x2, y1,y2 in zip(x, x[1:], y, y[1:]):
if y1 > y2:
plt.plot([x1, x2], [y1, y2], 'r')
elif y1 < y2:
plt.plot([x1, x2], [y1, y2], 'g')
else:
plt.plot([x1, x2], [y1, y2], 'b')
plt.show()