我正在使用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
我正在从默认存储库安装了matplotlib的Ubuntu 14.04 64位桌面版本计算机上使用Python 2.7(如果相关,我可以查找版本)。
实际上@tcaswell是正确的,因为该功能不存在,因此它返回false。您是否尝试过在绘图窗口上使用“缩放至矩形”按钮?那很好。如果还没有,请参考《交互式导航》中的matplotlib说明。您可以使用两种方式放大:
单击平移/缩放按钮:
按鼠标右键进行缩放,将其拖动到新位置。x轴将与向右移动成比例缩放,并与左向移动成比例缩小。
单击缩放到矩形按钮:
将鼠标放在某处和轴上,然后按鼠标左键。按住按钮的同时拖动鼠标到新位置并释放。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句