matplotlib |分组数据框图绘制问题

时间:2015-12-10 04:27:53

标签: python pandas matplotlib plot

我确信这已经在某个时候得到了解答,但我似乎无法找到正确的搜索条件来找出解决方案。我试图从分组数据框中绘制一系列线条,其中线条的颜色与数据框架上的分组键对齐。我在那里99%,但现在我得到一个奇数输出,其中绘图中的线的最终数据点重新连接到原点。我认为这与具有不同“长度”的x轴有关,具体取决于所绘制的系列。

sample image

编辑:以下是分组数据框中x和y的样子:

(2013,         team  year  month   x         y   z
Index                                      
665    team2  2013      1   6  0.003268   1
666    team2  2013      1   7  0.003390   1
667    team2  2013      1   8  0.006969   2
668    team2  2013      1   9  0.003571   1
669    team2  2013      1  10  0.011152   3
670    team2  2013      1  11  0.007634   2
671    team2  2013      1  12  0.028226   7
672    team2  2013      1  13  0.016949   4
673    team2  2013      1  14  0.022026   5
674    team2  2013      1  15  0.013761   3
675    team2  2013      1  16  0.023810   5
676    team2  2013      1  18  0.010204   2
677    team2  2013      1  19  0.021858   4
678    team2  2013      1  20  0.034091   6
679    team2  2013      1  21  0.046784   8
680    team2  2013      1  22  0.037975   6
681    team2  2013      1  23  0.020548   3
682    team2  2013      1  24  0.021277   3
683    team2  2013      1  25  0.021277   3
684    team2  2013      1  26  0.007407   1
685    team2  2013      1  27  0.015267   2
686    team2  2013      1  29  0.008130   1
687    team2  2013      1  30  0.016807   2
688    team2  2013      1  31  0.034783   4
689    team2  2013      1  33  0.028302   3
690    team2  2013      1  34  0.019048   2
691    team2  2013      1  35  0.038095   4
692    team2  2013      2   4  0.005405   1
693    team2  2013      2   6  0.016667   3
694    team2  2013      2   7  0.005848   1
     ...   ...    ...  ..       ...  ..
953    team2  2013     11  18  0.045767  20
954    team2  2013     11  19  0.057279  24
955    team2  2013     11  20  0.042079  17
956    team2  2013     11  21  0.027919  11
957    team2  2013     11  22  0.025907  10
958    team2  2013     11  23  0.029650  11
959    team2  2013     11  24  0.032787  12
960    team2  2013     11  25  0.030220  11
961    team2  2013     12   3  0.002621   2
962    team2  2013     12   4  0.006640   5
963    team2  2013     12   5  0.010782   8
964    team2  2013     12   6  0.009602   7
965    team2  2013     12   7  0.008368   6
966    team2  2013     12   8  0.018466  13
967    team2  2013     12   9  0.013043   9
968    team2  2013     12  10  0.019345  13
969    team2  2013     12  11  0.015291  10
970    team2  2013     12  12  0.023364  15
colors = {2013: 'r', 2014: 'b', 2015: 'g'}

fig, ax = plt.subplots()
labels = []

for key, grp in dqData[dqData['team'] == 'team1'].groupby(['year']):
    ax = grp.plot(ax=ax, kind='line', x='x', y='y', figsize=(10,10), xlim=(0,30), sharex= True,c = colors[key])
    labels.append(key)

lines, _ = ax.get_legend_handles_labels()
ax.legend(lines, labels, loc='best')
plt.show()

1 个答案:

答案 0 :(得分:0)

下面的解决方案。必须转动数据并创建NaN。

Uncaught error: Call to undefined function mssql_connect().