MMTTMM
稍后设置如果您不知道要绘制的地块数量,则可以在绘制颜色后直接使用来更改颜色,从而直接从地块中获取数量.lines,我使用以下解决方案:一些随机数据import matplotlib.pyplot as pltimport numpy as npfig1 = plt.figure()ax1 = fig1.add_subplot(111)for i in range(1,15): ax1.plot(np.array([1,5])*i,label=i)您需要的一段代码:colormap = plt.cm.gist_ncar #nipy_spectral, Set1,Paired colors = [colormap(i) for i in np.linspace(0, 1,len(ax1.lines))]for i,j in enumerate(ax1.lines): j.set_color(colors[i])ax1.legend(loc=2)结果如下: