Python 如何绘制多重折线图(意大利面图)?获得';无效的RGBA参数:2000';尝试时出错?

Python 如何绘制多重折线图(意大利面图)?获得';无效的RGBA参数:2000';尝试时出错?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有一个低于so5b的数据帧(不完整) 该数据框具有2000年至2015年期间每月的SO2值 year month so2 1 2000 11 17.3 2 2000 12 14.488888888888892 3 2001 1 14.377777777777778 4 2001 2 17.555555555555557 5 2001 3 13.955555555555556 6 2001 4 12

我有一个低于so5b的数据帧(不完整)

该数据框具有2000年至2015年期间每月的SO2值

    year    month   so2
1   2000    11  17.3
2   2000    12  14.488888888888892
3   2001    1   14.377777777777778
4   2001    2   17.555555555555557
5   2001    3   13.955555555555556
6   2001    4   12.299999999999999
7   2001    5   11.0
8   2001    6   11.81111111111111
9   2001    7   10.525
10  2001    8   11.512500000000003
11  2001    9   11.212499999999999
12  2001    10  12.1625
13  2001    11  14.2125
14  2001    12  13.4875
我想绘制多个折线图-每月so2值的趋势-每年。i、 e输出需要如下所示

现在,为了得到上面的图,我在下面尝试了多个链接中引用的图

so5b.info()
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for key, grp in so5b.groupby(['year']):
    ax = grp.plot(ax=ax, kind='line', x='month', y='so2', c=key, label=key)
    plt.show()
当我执行上述操作时,我得到以下错误

ValueError: Invalid RGBA argument: 2000
此外,我也不确定是否应该按年度分组,即so5b.groupby(['year']),因为每年每月都会对数据进行排序

我参考了下面的多个链接,但似乎并没有解决我的问题


谢谢你的帮助。TIA

您可以在plot命令中删除
c=key
。这就是错误的来源,对于
key=2000
plt
不理解颜色代码
2000
。因此:

fig, ax = plt.subplots(figsize=(10,6))
for key, grp in so5b.groupby('year'):
    ax = grp.plot(ax=ax, kind='line', x='month', y='so2', label=key)
plt.show()
给你:

或者您可以使用
seaborn

fig, ax = plt.subplots(figsize=(10,6))
sns.lineplot(x='month', y='so2', hue='year', data=so5b)
plt.show()

您可以在plot命令中删除
c=key
。这就是错误的来源,对于
key=2000
plt
不理解颜色代码
2000
。因此:

fig, ax = plt.subplots(figsize=(10,6))
for key, grp in so5b.groupby('year'):
    ax = grp.plot(ax=ax, kind='line', x='month', y='so2', label=key)
plt.show()
给你:

或者您可以使用
seaborn

fig, ax = plt.subplots(figsize=(10,6))
sns.lineplot(x='month', y='so2', hue='year', data=so5b)
plt.show()