简体   繁体   中英

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.

  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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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