我想做一个散点图,在上面我可以有两个“y”轴(y1轴=产量(Kg/ha),在右边;y2轴=面积(公顷),在左边),在年份“x”轴上。并显示“趋势线”。 提前谢谢
crops1 = pd.DataFrame({"x1": crops['Years'],
"y1_1": crops['Area_ha'],
"y1_2": crops['Yield_kg']})
crops2 = pd.DataFrame({"x2": crops['Years'],
"y2_1": crops['Area_ha'],
"y2_2": crops['Yield_kg']})
#plt.scatter(x,y)
fig, ax1 = plt.scatter(x1,y1)
ax2=ax1.twinx()
crops1.scatter(x="x1", y= ["y1_1"], ax=ax1, legend=False)
crops1.scatter(x="x1", y="y1_2", ax=ax2, legend=False, color="r")
crops2.scatter(x="x2", y="y2_1", ax=ax1, legend=False)
crops2.scatter(x="x2", y="y2_2", ax=ax2, legend=False, color="r")
熊猫散点图:https://pandas.pydata.org/pandas-docs/version/1.3/reference/api/pandas.DataFrame.plot.scatter.html
趋势线:How to add trendline in python matplotlib dot (scatter) graphs?
相关问题 更多 >
编程相关推荐