python - How to do a 3D plot with equal aspect ratio adjustable with datalim?
问题描述
I am plotting a set of Line3d objects in my axes3D. I want to keep all the axes with equal scale and eliminate the margins between the axes and the figure. And this needs to hold for any shape of the figure.
So far i have tried this:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_proj_type('ortho')
ax.set_aspect('equal', adjustable='datalim', anchor='C')
plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
ax.set_axis_on()
ax.plot3D([0,0], [0,0], [0,1], 'blue', marker='s', markersize=5)
ax.plot3D([0,1], [0,0], [1,1], 'blue', marker='s', markersize=5)
ax.plot3D([1,1], [0,1], [1,1], 'blue', marker='s', markersize=5)
plt.show()
That gives the following figure that clearly does not maintain the scale in each axis:
I also tried by changing:
ax.set_aspect('equal', adjustable='box', anchor='C')
It gives the following figure, that does keep the axis with equal scaled:
But this is not what i want since the axes do not cover the entire figure box, as can be seen when I zoom in the axes:
So basically i want something similar to the first figure, but with the axis limits changed so to maintain the axis aspect ratio, even when zooming in and out.
I have tried other alternatives such as axis('scaled')
without success. I know that for 2d plotting this works fine just by setting ax.set_aspect('equal')
(see link here),but it doesn't seem to be the case for 3D axes.
解决方案
推荐阅读
- java - 供应商::get 能否返回 null
- c# - 数据不显示在选择框中
- javascript - 如何在react redux中使用不同的参数调度相同的动作
- swift - 在 iOS11 中,尝试在 NavigationBar 中添加圆形图像作为 navigationItem 并且它没有剪裁其边缘
- regex - RegExp VBA:勉强量词不返回子匹配值
- javascript - 我使用什么方法来操作对象中的数组数据?(仅限伪代码)
- r - 计算粒子的实时位移:ifelse 的问题,在条件 for 循环内
- go - 有没有办法在 go 中处理通用函数
- python - 如何找到元组之间的周长?
- python - 如何在 cPanel (o2switch) 上运行 Python Discord 机器人