来自 Pivot Table 的 Matplotlib 线图:调整轴刻度标签的颜色

Matplotlib Line Graph from Pivot Table: Adjust Color of Axis Tick Labels

鉴于以下情况:

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)

如何调整 y 轴刻度标签的颜色?

我试过了:

ax1.set_xticklabels(t.Count,color='grey')

...但没有骰子。

此外,如果它们以几千为单位(即最上面的数字是 90000),我怎样才能让它们显示为 90K 或 90,000?

提前致谢!

我认为你需要:

ax.tick_params(axis='x', color='grey', labelcolor='grey')

编辑:

如果要显示90,000:

from matplotlib.ticker import FuncFormatter

ax.get_yaxis().set_major_formatter(FuncFormatter(lambda x, p: format(int(x), ',')))