禁用PyQ中的matplotlib小部件

2024-10-04 05:29:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pyQt应用程序,其中包含几个嵌入式matplotlib小部件(https://github.com/chipmuenk/pyFDA)。在

可以为每个绘图小部件关闭绘图的自动更新,以加快应用程序的速度(尤其是三维绘图可能需要相当长的时间)。在

不幸的是,我还没有完全禁用画布。我想做的是

class MplWidget(QWidget):
    """
    Construct a subwidget with Matplotlib canvas and NavigationToolbar
    """

    def __init__(self, parent):
        super(MplWidget, self).__init__(parent)
        # Create the mpl figure and construct the canvas with the figure
        self.fig = Figure()
        self.pltCanv = FigureCanvas(self.fig)
#-------------------------------------------------

self.mplwidget = MplWidget(self)
self.mplwidget.pltCanv.setEnabled(False) # <- this doesn't work

为了清楚地表明在这个小部件中没有什么可以交互的。有简单的解决方法吗?在


Tags: andtheself应用程序绘图init部件with
1条回答
网友
1楼 · 发布于 2024-10-04 05:29:27

你可以在上面放一块灰色半透明的贴片,使它变灰。为此,您可以创建一个矩形,将其zorder设置得非常高,并对其进行图形转换。要将其添加到an轴,可以使用ax.add_patch;但是要将其添加到具有3D轴的图形中,这将不起作用,您需要通过fig.patches.extend添加它。(见this answer

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot([1,3,2],[1,2,3],[2,3,2])

rect=plt.Rectangle((0,0),1,1, transform=fig.transFigure, 
                   clip_on=False, zorder=100, alpha=0.5, color="grey")
fig.patches.extend([rect])

plt.show()

enter image description here

断开所有事件

您可以断开所有事件与画布的连接。这将阻止任何用户交互,但也是不可逆的;因此,如果您需要在稍后阶段返回这些事件,则解决方案将更加复杂。在

^{pr2}$

相关问题 更多 >