title: strange behaviour of pyplotlib upper menubar
body: <p>I am willing to integrate a matplotlib figure into a GUI designed with pyqt5:
  I wrote the code above:</p>
  <pre><code>from PyQt5 import QtCore, QtWidgets
  from PyQt5.QtWidgets import QMainWindow
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
  import matplotlib.pyplot as plt
  import random
  
  class Ui_MainWindow(QMainWindow):
  
      def setupUi(self, MainWindow):
  
  
  
          self.vbox = QtWidgets.QVBoxLayout()
          MainWindow.setObjectName(&quot;MainWindow&quot;)
          MainWindow.resize(1056, 600)
          self.vbox2 = MainWindow.layout()
  
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName(&quot;centralwidget&quot;)
  
          self.lineEdit_x = QtWidgets.QLineEdit(self.centralwidget)
          self.lineEdit_x.setGeometry(QtCore.QRect(550, 430, 40, 20))
          self.lineEdit_x.setObjectName(&quot;lineEdit_x&quot;)
          self.lineEdit_x.setText(str(1))
          self.lineEdit_y = QtWidgets.QLineEdit(self.centralwidget)
          self.lineEdit_y.setGeometry(QtCore.QRect(595, 430, 40, 20))
          self.lineEdit_y.setObjectName(&quot;lineEdit_y&quot;)
          self.lineEdit_y.setText(str(1))
          self.label_3 = QtWidgets.QLabel(self.centralwidget)
          self.label_3.setGeometry(QtCore.QRect(490, 430, 66, 13))
          self.label_3.setObjectName(&quot;label_3&quot;)
  
          self.figure = plt.figure()#figsize=(40, 10), dpi=18)
          self.canvas = FigureCanvas(self.figure)
          #self.canvas.mpl_connect(&quot;button_release_event&quot;, self.on_release)
          self.canvas.mpl_connect(&quot;button_press_event&quot;, self.on_press)
          self.canvas.setGeometry(QtCore.QRect(0,30, 400, 400))
  
          self.toolbar = NavigationToolbar(self.canvas,  self)
          self.vbox2.addWidget(self.toolbar)
          self.vbox2.addWidget(self.canvas)
          self.plot()
  
  
  
  
          MainWindow.setCentralWidget(self.centralwidget)
          self.menubar = QtWidgets.QMenuBar(MainWindow)
          self.menubar.setGeometry(QtCore.QRect(0, 0, 1056, 21))
          self.menubar.setObjectName(&quot;menubar&quot;)
          MainWindow.setMenuBar(self.menubar)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName(&quot;statusbar&quot;)
          MainWindow.setStatusBar(self.statusbar)
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def plot(self):
          data = [random.random() for i in range(23)]
          ax = self.figure.add_subplot(111)
          ax.plot(data, 'r-', linewidth=0.5)
          ax.set_title('PyQt Matplotlib Example')
          self.canvas.draw()
      def on_press(self, event):
          self.lineEdit_x.setText(str(event.x))
          self.lineEdit_y.setText(str(event.y))
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate(&quot;MainWindow&quot;, &quot;MainWindow&quot;))
  
          self.label_3.setText(_translate(&quot;MainWindow&quot;, &quot;Center (x,y)&quot;))
  
  
  if __name__ == &quot;__main__&quot;:
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  </code></pre>
  <p><a href="https://i.stack.imgur.com/UjbKt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UjbKt.png" alt="enter image description here" /></a></p>
  <p>as one can see I have 2 issues:</p>
  <ol>
  <li>the menu bar is detached from the figure and reduced</li>
  <li>the axes are smaller than the figure field.
  so can someone please check my code to address these two issues <strong>with minimum modifications</strong>
  thanks</li>
  </ol>