Python 如何定义“中直方图的颜色”;groupby;?

Python 如何定义“中直方图的颜色”;groupby;?,python,pandas,colors,histogram,Python,Pandas,Colors,Histogram,我需要为下一个示例定义客户端颜色(“F”和“M”有两种颜色): d = {'gender' : Series(['M', 'F', 'F', 'F', 'M']),'year' : Series([1900, 1910, 1920, 1920, 1920])} df = DataFrame(d) grouped = df.groupby('gender').year grouped.plot(kind='hist',legend=True) 如果您不需要groupby(我看不出在这种情况下它

我需要为下一个示例定义客户端颜色(“F”和“M”有两种颜色):

d = {'gender' : Series(['M', 'F', 'F', 'F', 'M']),'year' : Series([1900, 1910, 1920, 1920, 1920])}
df = DataFrame(d)

grouped = df.groupby('gender').year
grouped.plot(kind='hist',legend=True)
如果您不需要groupby(我看不出在这种情况下它会给您带来什么好处),那么您可以轻松设置颜色:

ax1 = plt.subplot(111)
df[df['gender']=='M'].hist(ax=ax1, color='red', label='M')
df[df['gender']=='F'].hist(ax=ax1, color='blue', label='F')
ax1.legend(loc='best')