Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 图例颜色与seaborn不匹配_Python_Matplotlib_Seaborn - Fatal编程技术网

Python 图例颜色与seaborn不匹配

Python 图例颜色与seaborn不匹配,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我正在使用sns.pointplot,由于没有标签属性,我决定创建自定义图例,但我的问题是颜色不匹配 我的数据框如下所示: deploy deployed_today_rent total_rent cum_deploy hourly percent cum_percent 10min 2019-10-01 05:30:00 6 0 0 6 0.000000 0.0

我正在使用sns.pointplot,由于没有
标签
属性,我决定创建自定义图例,但我的问题是颜色不匹配

我的数据框如下所示:

                  deploy    deployed_today_rent total_rent  cum_deploy  hourly percent  cum_percent
10min                       
2019-10-01 05:30:00 6           0   0   6   0.000000    0.000000
2019-10-01 05:40:00 0           0   0   6   0.000000    0.000000
2019-10-01 05:50:00 6           0   0   12  0.000000    0.000000
2019-10-01 06:00:00 13          0   0   25  0.000000    0.000000
2019-10-01 06:10:00 0           0   0   25  0.000000    0.000000
2019-10-01 06:20:00 0           1   1   25  0.040000    0.040000
2019-10-01 06:30:00 0           0   0   25  0.000000    0.040000
2019-10-01 06:40:00 0           1   1   25  0.040000    0.080000
2019-10-01 06:50:00 1           1   1   26  0.038462    0.118462

fig,(ax1)= plt.subplots(nrows=1)
fig.set_size_inches(22,17)

sns.pointplot(data=test, x=test.index, y="total_rent", ax=ax1,color="blue", label="total")
sns.pointplot(data=test, x=test.index, y="deployed_today_rent", ax=ax1, color="green", label="deployed_rent")
sns.pointplot(data=test, x=test.index, y="cum_deploy", ax=ax1, color="#BEC647", label="cum_deploy")

ax1.legend(labels=["total", "deployed_rent", "cum_deploy"], fontsize=15)

plt.savefig("test.png", dpi=300, bbox_inches="tight");
它成功创建了图例,但图例中的颜色与线条不匹配

从中,您可以通过如下方式为每一行创建“代理艺术家”
matplotlib.lines.Line2D

从matplotlib.lines导入Line2D
a=Line2D([]、[]、颜色为蓝色、标签为总计)
b=Line2D([]、[]、颜色为绿色、标签为已部署)
c=Line2D([]、[]、颜色='BEC647',标签='cum#u deploy')
plt.legend(句柄=[a,b,c])

这应该会生成一个图例,其中有三条默认宽度的不同颜色线以及各自的标签。

您可以提供屏幕截图和/或用于打印的数据,以便我测试您的代码吗?