0

I'm trying to plot 2 scatterplots next to each other using pyplot, but I can't get it to work.

x1 = list(stablepdfs.keys())
y1 = list(stablepdfs.values())
plt.scatter(x1,y1)

plt.title('Size of Succeeded vs Failed Pdfs')
plt.xlabel('Pdf Size in MB')
plt.ylabel('# of Pdfs')

plt.subplot(211)
#-----------------------------------
x2 = list(unstablepdfs.keys())
y2 = list(unstablepdfs.values())
plt.scatter(x2,y2, c='r')

plt.title('Size of Succeeded vs Failed Pdfs')
plt.xlabel('Pdf Size in MB')
plt.ylabel('# of Pdfs')

plt.subplot(212)

plt.show()

However, I only see one plot.

enter image description here

Interestingly, when I reverse the order of the code and plot the other one first, now I am only able to see the other plot.

x2 = list(unstablepdfs.keys())
y2 = list(unstablepdfs.values())
plt.scatter(x2,y2, c='r')

plt.title('Size of Succeeded vs Failed Pdfs')
plt.xlabel('Pdf Size in MB')
plt.ylabel('# of Pdfs')

plt.subplot(212)

#-----------------------------------

x1 = list(stablepdfs.keys())
y1 = list(stablepdfs.values())
plt.scatter(x1,y1)

plt.title('Size of Succeeded vs Failed Pdfs')
plt.xlabel('Pdf Size in MB')
plt.ylabel('# of Pdfs')

plt.subplot(211)

plt.show()

enter image description here

wheeeee
  • 1,046
  • 2
  • 14
  • 33
  • 1
    `fig, axs = plt.subplots(ncols=2)` for starters – BigBen Apr 03 '23 at 17:59
  • 1
    90% of the questions tagged `matplotlib` stem from using the non object-oriented approach. – Guimoute Apr 03 '23 at 18:01
  • Non-object oriented or not, `plt.subplot(2,1,1)` _creates_ the subplot you are going to plot in, so it should come before the other commands, not after. – Jody Klymak Apr 03 '23 at 18:58
  • Does this answer your question? [How to plot in multiple subplots](https://stackoverflow.com/questions/31726643/how-to-plot-in-multiple-subplots) – Jody Klymak Apr 03 '23 at 19:02

0 Answers0