红颜莎娜
一个最小的工作示例可以是import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.collections import LineCollectionx = np.linspace(0,1, 100)y = np.linspace(0,1, 100)cols = np.linspace(0,1,len(x))points = np.array([x, y]).T.reshape(-1, 1, 2)segments = np.concatenate([points[:-1], points[1:]], axis=1)fig, ax = plt.subplots()lc = LineCollection(segments, cmap='viridis')lc.set_array(cols)lc.set_linewidth(2)line = ax.add_collection(lc)fig.colorbar(line,ax=ax)