1

I have 3 scatter plots, was wondering how I can combine these 3 into 1 big scatter plot.

I can't seem to find a solution to this specific problem using only Matplotlib.

x1 = np.random.randint(40, 100, 50)
y1 = np.random.randint(40, 100, 50)

x2 = np.random.randint(0, 60, 50)
y2 = np.random.randint(0, 60, 50)

x3 = np.random.randint(40, 100, 50)
y3 = np.random.randint(0, 60, 50)

fig, (plot1, plot2, plot3, plot4) = plt.subplots(1, 4)

plot1.scatter(x1,y1, color='green', s = 10)
plot1.set(xlim=(0, 100), ylim=(0, 100))

plot2.scatter(x2,y2, color='red', s = 10)
plot2.set(xlim=(0, 100), ylim=(0, 100))

plot3.scatter(x3,y3, color='blue', s = 10)
plot3.set(xlim=(0, 100), ylim=(0, 100))

plot4.scatter(plot1, plot2, plot3)

so I want plot4 to be a combination of plot1, plot2 and plot3.

Kenneth Wong
  • 43
  • 2
  • 11

2 Answers2

0

Simply plot each original plot on plot4:

plot4.scatter(x1,y1, color='green', s = 10)
plot4.scatter(x2,y2, color='red', s = 10)
plot4.scatter(x3,y3, color='blue', s = 10)

enter image description here

Alternatively, you can combine each x and y array using np.concatenate() to call the plot command only once, but this loses the ability to color each sub-group independently.

plot4.scatter(np.concatenate((x1,x2,x3)), 
              np.concatenate((y1,y2,y3)), 
              color='black', s=10)
Brendan
  • 3,901
  • 15
  • 23
0

If the colour of the plot4 can be different than the original ones, you can do as follows:

fig, (plot1, plot2, plot3, plot4) = plt.subplots(1, 4)

plot1.scatter(x1,y1, color='green', s = 10)
plot1.set(xlim=(0, 100), ylim=(0, 100))

plot2.scatter(x2,y2, color='red', s = 10)
plot2.set(xlim=(0, 100), ylim=(0, 100))

plot3.scatter(x3,y3, color='blue', s = 10)
plot3.set(xlim=(0, 100), ylim=(0, 100))

plot4.scatter([x1, x2, x3], [y1, y2, y3], color=('violet'), s = 10)

enter image description here

But if you want the colours of all the plots to be the same as they are in the three subplots, you can do what Brendan has suggested

some_programmer
  • 3,268
  • 4
  • 24
  • 59