Python Matplotlib:在一行上显示多个标签

Python Matplotlib:在一行上显示多个标签,python,pandas,matplotlib,legend,Python,Pandas,Matplotlib,Legend,我有一个DF,像这样: DF=pd.DataFrame.from_dict({"date":["2019-01-01","2019-01-02","2019-01-03","2019-01-04","2019-01-05","2019-01-06","2019-01-07","2019-01-08","201

我有一个DF,像这样:

DF=pd.DataFrame.from_dict({"date":["2019-01-01","2019-01-02","2019-01-03","2019-01-04","2019-01-05","2019-01-06","2019-01-07","2019-01-08","2019-01-09","2019-01-10"],
                           "temperature":[9,7,5,14,17,18,16,13.5,19,21],
                           "shorter_opinion":["bad & very bad","bad & very bad","bad & very bad","not good not bad","good & very good", "good & very good", "good & very good","not good not bad","not good not bad","bad & very bad"]})
为了使每个DF[“shorter_opinion”]值都有一种颜色,我将一个dict包装起来,并显示如下:

colors={"good & very good":"green","not good not bad":"yellow","bad & very bad":"red"}

plt.figure()
plt.scatter(x = DF["date"], y = DF["temperature"], c=DF["shorter_opinion"].map(colors))
plt.xticks(DF["date"][::3])
plt.legend(loc="upper right")
plt.show()
plt.figure()
plt.scatter(x = DF["date"], y = DF["temperature"], c=DF["shorter_opinion"].map(colors), label=DF["shorter_opinion"].unique())
plt.xticks(DF["date"][::3])
patches = [ plt.plot([],[], marker="o", ms=10, ls="", mec=None, color=colors[i], 
            label=i)[0]  for i in colors.keys() ]
plt.legend(colors.keys())
plt.show()
我试着用Serie.Unique()在传奇中展示这首单曲的状态

但我有这张照片


如何修改此代码,使每个值都位于正确的颜色旁边?

一种解决方案是使用补丁,如下所示:

colors={"good & very good":"green","not good not bad":"yellow","bad & very bad":"red"}

plt.figure()
plt.scatter(x = DF["date"], y = DF["temperature"], c=DF["shorter_opinion"].map(colors))
plt.xticks(DF["date"][::3])
plt.legend(loc="upper right")
plt.show()
plt.figure()
plt.scatter(x = DF["date"], y = DF["temperature"], c=DF["shorter_opinion"].map(colors), label=DF["shorter_opinion"].unique())
plt.xticks(DF["date"][::3])
patches = [ plt.plot([],[], marker="o", ms=10, ls="", mec=None, color=colors[i], 
            label=i)[0]  for i in colors.keys() ]
plt.legend(colors.keys())
plt.show()