首页 > 解决方案 > 如何在 python 中绘制基于散点图的 2 x 2 三维图,以使它们均匀分布在图中?

问题描述

这些是我使用 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()中汲取了灵感。

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

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

标签: pythonmatplotlibscatter-plotscatterscatter3d

解决方案


这应该做你想要的:

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

推荐阅读