How to plot a multicolored curve using a single plot command in matplotlib

后端 未结 2 620
我在风中等你
我在风中等你 2021-01-21 06:30

If I understand correctly, the function:

matplotlib.pyplot.plot(x, y)

plots len(x)-1 separate line segments - one going from (x[0], y[0]) to (x

相关标签:
2条回答
  • 2021-01-21 06:50

    You should be able to use matplotlib.collections.LineCollection which accepts a colors parameter (sequence of RGBA tuples).

    0 讨论(0)
  • 2021-01-21 06:52

    If you implement a colorbar, something similar to this, then you should be able to do it in one line. The trick may be to pick a colorscale that changes on the order of your line segments.

    0 讨论(0)
提交回复
热议问题