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

Viewed 17

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.

  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. It shows only red data(test data) in the output.

1 Answers

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.

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()
Related