我正在使用 matplotlib 生成 3D 图。我希望能够放大感兴趣的区域。目前,我可以平移但不能缩放。查看mplot3d API,我了解了 can_pan():
Return True if this axes supports the pan/zoom button functionality.
3D axes objects do not use the pan/zoom button.
和 can_zoom():
Return True if this axes supports the zoom box button functionality.
3D axes objects do not use the zoom box button.
它们都返回 False(我认为 can_pan 返回 False,因为轴不能平移和缩放,但也许我读错了 API)。
有没有办法启用缩放? API 指示它不使用按钮。有什么方法可以启用缩放或将其设置为 can_pan()
和 can_zoom()
返回 True
?
这是代码片段:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
data = np.genfromtxt('data_file.txt')
fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
ax1.scatter(data[:,0],data[:,1],data[:,2], c='r', marker='.')
plt.show()
ax1.can_zoom()
>>> False
ax1.can_pan()
>>> False
我在 Ubuntu 14.04 64 位桌面版机器上使用 Python 2.7,并从默认存储库安装了 matplotlib(如果相关,我可以查看版本)。
原文由 Steven C. Howell 发布,翻译遵循 CC BY-SA 4.0 许可协议
实际上 @tcaswell 是正确的,这个功能不存在,所以它返回 false。您是否尝试过绘图窗口上的缩放到矩形按钮?这非常有效。如果您还没有,请参阅 交互式导航 上的 matplotlib 说明。您可以使用两种方式放大: