鉴于以下内容:
import pandas as pd
import numpy as np
%matplotlib inline
df = pd.DataFrame(
{'YYYYMM':[201603,201503,201403,201303,201603,201503,201403,201303],
'Count':[5,6,2,7,4,7,8,9],
'Group':['A','A','A','A','B','B','B','B']})
df['YYYYMM']=df['YYYYMM'].astype(str).str[:-2]
t=df.pivot_table(df,index=['YYYYMM'],columns=['Group'],aggfunc=np.sum)
fig, ax = plt.subplots(1,1)
t.plot(ax=ax)
t.plot()中是否有参数允许我指定每一行的颜色?
提前致谢!
答案 0 :(得分:1)
您可以使用:
ax.set_color_cycle(['red', 'black'])
样品:
df = pd.DataFrame(
{'YYYYMM':[201603,201503,201403,201303,201603,201503,201403,201303],
'Count':[5,6,2,7,4,7,8,9],
'Group':['A','A','A','A','B','B','B','B']})
df['YYYYMM']=df['YYYYMM'].astype(str).str[:-2]
t=df.pivot_table(df,index=['YYYYMM'],columns=['Group'],aggfunc=np.sum)
fig, ax = plt.subplots(1,1)
ax.set_color_cycle(['red', 'black'])
t.plot(ax=ax)
编辑:
非常有趣,似乎更好的是使用全名的颜色,因为它与Mike 1. answer不同:
t.plot(ax=ax, style=['yellow', 'red'])
答案 1 :(得分:1)