【问题标题】:Disable coordinates from the toolbar of a Matplotlib figure从 Matplotlib 图的工具栏中禁用坐标
【发布时间】:2016-06-30 23:17:58
【问题描述】:

我正在一个使用 PyQt4 和 Matplotlib 库的项目中工作。我创建了一个 matplotlib 图并添加了一个工具栏。

有没有办法禁用其中显示的坐标?我的意思是这些:

我想这样做,因为我要在工具栏中添加一些按钮,我需要这个空间。

这是matplotlib图的代码:

class Figure(QMainWindow):
  def __init__(self):
    QMainWindow.__init__(self)

    self.linedit = SelectData(self)

    self.mainWidget = QWidget()
    self.setCentralWidget(self.mainWidget)

    layout = QVBoxLayout()
    self.mainWidget.setLayout(layout)

    self.figure_canvas = FigureCanvas(Figure())
    layout.addWidget(self.figure_canvas, 10)

    self.axes = self.figure_canvas.figure.add_subplot(211)
    self.axes.grid(False)

    #I added this toolbar
    self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)
    self.addToolBar(Qt.TopToolBarArea, self.navigation_toolbar)

我是python新手,希望你能帮助我。谢谢你的回答。

【问题讨论】:

    标签: python matplotlib pyqt


    【解决方案1】:

    您可以重新分配坐标轴 format_coord 以显示您喜欢的任何内容(例如,请参阅 this answerthis answer)。

    所以要完全禁用它,您可以将其设置为空字符串,如下所示:

    self.axes.format_coord = lambda x, y: ""
    

    【讨论】:

    • 感谢您的回答。这行得通!我以前看的时候没有找到这些答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多