def __new__(self, ax, y, x=None, color=None, cmap='inferno', pltargs={}, **kwargs):
# Check inputs :
y = np.ravel(y)
if x is None:
x = np.arange(len(y))
else:
x = np.ravel(x)
if len(y) != len(x):
raise ValueError('x and y must have the same length')
if color is None:
color = np.arange(len(y))
# Create segments:
xy = np.array([x, y]).T[..., np.newaxis].reshape(-1, 1, 2)
segments = np.concatenate((xy[0:-1, :], xy[1::]), axis=1)
lc = LineCollection(segments, cmap=cmap, **pltargs)
lc.set_array(color)
# Plot managment:
ax.add_collection(lc)
plt.axis('tight')
_pltutils.__init__(self, ax, **kwargs)
return plt.gca()
评论列表
文章目录