mahmood
mahmood

Reputation: 24665

Using add_subplot for multiple plots in a figure

I use the following code to place two plots on left and right of the plane. However, as you can see the plots have overlap. How can I fix that?

fig = plt.figure(figsize = (16,8))
ax = fig.add_subplot(1, 1, 1)
ax.scatter( F1, F2, c=colors )

ax2 = fig.add_subplot(1, 2, 2)
ax2.scatter( F1, F3, c=colors )

enter image description here

Upvotes: 0

Views: 461

Answers (1)

abc
abc

Reputation: 11929

You are creating overlapping subplots

ax = fig.add_subplot(1, 1, 1) # 1 row 1 col # pos 1
ax2 = fig.add_subplot(1, 2, 2) # 1 row, 2 col # pos 2

If you want to divide the plot space by 2 you should use:

ax = fig.add_subplot(121)
ax2 = fig.add_subplot(122)

Upvotes: 2

Related Questions