如何在 python 中绘制基于散点的子图的 2 x 2 三维图形,使它们均匀分布在图中?

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?

这些是我使用 matplotlib 绘制图形的配置

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

我尝试了 fig.add_plot() 第一个参数的许多不同组合,并从这个 document 中汲取了灵感。

如果不值得麻烦的话,我目前正在考虑将它们分开绘制。

所以问题是,如何在 python 中绘制基于散点图的 2 x 2 三维图,使它们均匀分布在图中?我当前的代码将这些图压在一起

这应该可以满足您的要求:

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