0

These are my configurations using matplotlib for my plotting figures

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax_tl = fig.add_subplot(211, projection='3d')
ax_br = fig.add_subplot(221, projection='3d')
ax_Y0 = fig.add_subplot(212, projection='3d')
ax_Y1 = fig.add_subplot(222, projection='3d')

I tried many different combinations of fig.add_plot() first argument and drew inspiration from this document.

Im currently considering just to plot them separately if its not worth the hassle.

So the question is, how do I plot a 2 x 2 three dimensional figure of scatter based subplots in python to make them evenly spread out across the figure? My current code makes the plots squished together

pysolver33
  • 307
  • 1
  • 5
  • 13
  • do you mean something like this: [matploblib 2D collections in 3D](https://matplotlib.org/stable/gallery/mplot3d/2dcollections3d.html) ? – mozway Sep 14 '21 at 17:23
  • nope, I need to plot a 2 x 2 figure of 3d subplots that is evenly spread out across the figure so as to make it more easily readable. My current code makes the plots squished together – pysolver33 Sep 14 '21 at 17:30

1 Answers1

1

This should do what you want:

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
spec = gridspec.GridSpec(ncols=2, nrows=2, figure=fig)
ax_tl = fig.add_subplot(spec[0, 0], projection='3d')
ax_br = fig.add_subplot(spec[0, 1], projection='3d')
ax_Y0 = fig.add_subplot(spec[1, 0], projection='3d')
ax_Y1 = fig.add_subplot(spec[1, 1], projection='3d')
Jethro Cao
  • 968
  • 1
  • 9
  • 19