简体   繁体   English

Matplotlib 当我想用

[英]Matplotlib doesn't show both datasets points on the figure when I want to create scatter plot with

I'm sure that I've done all things right but in the end the result I got is a sccatter plot that only shows the second datasets data.我确信我做的一切都是正确的,但最终我得到的结果是一个只显示第二个数据集数据的散点 plot。

  fig = plt.figure()
  ax1 = fig.add_subplot(111)
  ax1.scatter(train["ENGINESIZE"], train["CO2EMISSIONS"], color = "green")
  ax1.scatter(test["ENGINESIZE"], test["CO2EMISSIONS"], color = "red")
  plt.xlabel("Engine Size")
  plt.ylabel("Emission")
  
  plt.show()

Here You can see what's going on in my output in link below.在这里,您可以在下面的链接中看到我的 output 中发生了什么。 It shows only red data(test data) in the output.它仅显示 output 中的红色数据(测试数据)。

Where is the "output link below", please?请问“下面的输出链接”在哪里? For now I can only imagine what you are describing.现在我只能想象你在描述什么。

Also it helps if both plots have the same axis.如果两个图具有相同的轴,它也会有所帮助。 That is, both have the same x-axis and then they can vary on their y-axis.也就是说,两者都有相同的 x 轴,然后它们可以在 y 轴上变化。

If so:如果是这样:

fig, ax = plt.subplots()

df.plot(kind = 'scatter', x= train["ENGINESIZE"], y = train["CO2EMISSIONS"], color = {'g'}, ax = ax)
df.plot(kind = 'scatter', x= test["ENGINESIZE"], y = test["CO2EMISSIONS"], color = {'r'}, ax = ax)
plt.xlabel()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM