我在matplotlib工具栏中添加了一个名为“选择点”的小部件,它允许我在体形窗口中选择一组点并将它们写入文件。这个很好用。但是,如果我之前必须在单击工具栏上的“我的小部件”按钮之前缩放或平移到感兴趣的区域,缩放或平移模式将保持活动状态,并且我无法使用小部件按钮选择我的点,除非我再次手动单击工具栏上的“缩放/平移”按钮以停用这些模式。单击“我的小部件”按钮时,是否有方法以编程方式退出缩放或平移模式?这是一个小痛苦,但一个很好的特点,我想有
我已经试着查看了所有plt.gcf().canvas方法,但似乎找不到可以从代码中选择/取消选择工具栏模式的位置
---将名为“选择点”的工具栏小部件按钮链接到getPoints类的部分代码----
# Get figure handles
figNum = plt.gcf()
ax = plt.gca()
pts = ax.collections[-1]
# Route 'Select Points' button to matplotlib figure window
fig1.canvas.manager.toolmanager.add_tool('Select Points', getPoints, figNum = figNum, ax = ax, pts = pts, outPath = outPath, origTitle = origTitle)
fig1.canvas.manager.toolbar.add_tool('Select Points', 'navigation', 3)
---获取积分类--
class getPoints(ToolToggleBase):
default_toggled = False
def __init__(self, *args, figNum, ax, pts, outPath, origTitle, **kwargs):
# Initialize base variables
self.figNum = figNum
self.ax = ax
self.pts = pts
self.outPath = outPath
self.origTitle = origTitle
# Call super-initialized variables
super().__init__(*args, **kwargs)
def enable(self, *args, **kwargs):
# Get inputs for getPlotPts function
figNum = self.figNum
ax = self.ax
pts = self.pts
outPath = self.outPath
origTitle = self.origTitle
onState = True
# Call getPlotPts function
getPlotPts(self, figNum, ax, pts, outPath, origTitle, onState)
def disable(self, *args, **kwargs):
# Get inputs for getPlotPts function
figNum = self.figNum
ax = self.ax
pts = self.pts
outPath = self.outPath
origTitle = self.origTitle
onState = False
# Call getPlotPts function
getPlotPts(self, figNum, ax, pts, outPath, origTitle, onState)
目前没有回答
相关问题 更多 >
编程相关推荐