【发布时间】:2020-05-14 04:25:48
【问题描述】:
我正在从一个类中的数据框“self.data”中绘制一些曲线。数据框的每一列都是一条曲线,列名写在行尾。
我为此制作了这个程序:
cmap = plt.cm.get_cmap('brg', len(self.data.columns)+1)
for i in range(len(self.data.columns)): #plot curves and add legend
self.courbe.plot(self.data[self.data.columns[i]],c=cmap(i))
angle=20
self.courbe.annotate(self.data.columns[i],
xy= (max(self.data.index),self.data.at[max(self.data.index),self.data.columns[i]]),
textcoords='offset points',
xytext=(2, 0),
va='bottom',
rotation=angle,c=cmap(i))
所以我使用了“brg”颜色图,但我只想使用该颜色图的一部分(例如删除浅绿色部分)。
我在 stackoverflow 上尝试了一些建议的解决方案,例如 how to extract a subset of a colormap as a new colormap in matplotlib?,但所有曲线的颜色都相同。有人知道另一种方法吗?
谢谢,祝你有美好的一天:)
【问题讨论】:
标签: python python-3.x pandas matplotlib colormap