首页 > 解决方案 > 使用 matplotlib 在同一图形上绘制折线图

问题描述

我试图在同一个图上绘制两个折线图,但这些图是单独打印的。我过滤了数据并制作了两个折线图。如何在同一个图形上合并两个图形?

代码:

#getting columns with Primary type and arrest type

arrFalse=arrPri.loc[(arrPri["Primary Type"]== "ARSON") & (arrPri.Arrest == False),["count","Year"]]
arrTrue=arrPri.loc[(arrPri["Primary Type"]== "ARSON") & (arrPri.Arrest == True),["count","Year"]]

#plotting the graphs
arrFalse.plot(x="Year",y="count",kind="line",figsize=(10,5),color="red")
arrTrue.plot(x="Year",y="count",kind="line",figsize=(10,5),color="olive",linestyle="dashed")
plt.xlabel(uPri[i])
plt.legend(crimes.Arrest)
plt.title(uPri[i] + " Vs Crime count")
plt.show()

`

标签: python-3.xpandasmatplotlibdata-visualization

解决方案


推荐阅读