如何在等高比相等的3D图周围获得紧密的框

时间:2018-10-24 09:38:32

标签: matplotlib

我正在绘制细长的3D结构,如导线。

具有相等的纵横比很重要,但是我发现的方法会导致很多空白。

这是我的尝试

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

x = [-10, 10]
y = [-1, 1]
for s, e in combinations(np.array(list(product(x, y, y))), 2):
    sum_ = np.sum(np.abs(s - e))
    lines = sum_ == x[1] - x[0]
    square = sum_ == y[1] - y[0]
    if lines or square:
        ax.plot3D(*zip(s, e), color=("b" if lines else "r"))

ax.auto_scale_xyz(x, x, x)  # to get the equal aspect ratio

产生的结果

fake wire

实际上,电线的纵横比甚至更大,但出于演示目的,我将其保留为这样。

我的目标是缩小导线周围的空白空间。

我在GitHub上发现了this可能与之相关的问题。

StackOverflow上也有this问题,但要接受的答案需要修改Matplotlib的源代码。

0 个答案:

没有答案