我正在创建一个带有图例的简单 PyQtGraph 图,我想禁用所有交互性。
我可以禁用平移和缩放以及右键单击上下文菜单,但仍然可以移动图例。如何防止用户用鼠标拖动图例?
import pyqtgraph as pg
widget = pg.plot()
# Disable interactivity
widget.setMouseEnabled(x=False, y=False) # Disable mouse panning & zooming
widget.hideButtons() # Disable corner auto-scale button
widget.getPlotItem().setMenuEnabled(False) # Disable right-click context menu
widget.addLegend(enableMouse=False) # This doesn't disable legend interaction
widget.plot([1, 3, 2, 5, 4], name="Example plot")
if __name__ == "__main__":
pg.exec()