title: How to graph, from a CSV file using Matpotlib and PyQt5
body: <p>I'm trying to adapt this code to PyQt5 (Source: <a href="http://songhuiming.github.io/pages/2016/05/31/read-in-csv-and-plot-with-matplotlib-in-pyqt4/" rel="nofollow noreferrer">http://songhuiming.github.io/pages/2016/05/31/read-in-csv-and-plot-with-matplotlib-in-pyqt4/</a> )</p>
  
  <pre><code>from PyQt5 import QtGui,QtWidgets
  import sys
  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  from matplotlib import style
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  
  style.use('ggplot')
  
  
  class PrettyWidget(QtWidgets.QMainWindow):
  
  
      def __init__(self):
          super().__init__()
          #super(PrettyWidget, self).__init__()
          self.initUI()
  
      def initUI(self):
          self.setGeometry(600,300, 1000, 600)
          self.center()
          self.setWindowTitle('Revision on Plots, Tables and File Browser')     
          #Grid Layout
          grid = QtWidgets.QGridLayout()
          self.setLayout(grid)
  
          #Import CSV Button
          btn1 = QtWidgets.QPushButton('Import CSV', self)
          btn1.resize(btn1.sizeHint())
          btn1.clicked.connect(self.getCSV)
          grid.addWidget(btn1, 1, 0)
  
  
  
          #Canvas and Toolbar
          self.figure = plt.figure(figsize=(15,5))    
          self.canvas = FigureCanvas(self.figure)     
          grid.addWidget(self.canvas, 2,0,1,2)
  
  
          #DropDown mean / comboBox
  
          self.df = pd.DataFrame()
          self.rating_list = []
          self.yq_list = []
  
          self.comboBox = QtWidgets.QComboBox(self)
          self.comboBox.addItems(self.rating_list)
          grid.addWidget(self.comboBox, 0, 0)
  
          self.comboBox2 = QtWidgets.QComboBox(self)
          self.comboBox2.addItems(self.yq_list)
          grid.addWidget(self.comboBox2, 0, 1)
  
          #Plot Button
          btn2 = QtWidgets.QPushButton('Plot', self)
          btn2.resize(btn2.sizeHint())    
          btn2.clicked.connect(self.plot)
          grid.addWidget(btn2, 1, 1)
  
          self.show()
  
  
      def getCSV(self):
          filePath = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '/home')
          print (filePath)
          self.df = pd.read_csv(str(filePath))
          self.rating_list = self.df.rating.unique().tolist()
          self.yq_list = [str(x) for x in self.df.yq.unique().tolist()]       
          self.comboBox.addItems(self.rating_list)
          self.comboBox2.addItems(self.yq_list)
          print (self.rating_list)
  
  
      def plot(self):
          y = []
          for n in range(3):
              try:
                  y.append(self.table.item(0, n).text())
              except:
                  y.append(np.nan)
  
          p1 = self.df.ix[(self.df.rating ==  str(self.comboBox.currentText())) &amp; (self.df.yq ==  int(str(self.comboBox2.currentText()))), :]
          print (p1)
  
          plt.cla()
  
  
          ax = self.figure.add_subplot(111)
          ax.plot(p1.ix[:, 0], 'g', label = "Pred on data with Model")
          ax.plot(p1.ix[:, 1], label = "adj Pred to non-decreasing")
          ax.plot(p1.ix[:, 3], label = "Fitting value in Model")
          ax.plot(p1.ix[:, 2], 'r', label = "Actual PD")
          ax.plot(p1.ix[:, 4], 'y', label = "Long Run Avg")
  
          ax.set_title('Canada C&amp;I PD Plot')
          ax.legend(loc = 0)
          self.canvas.draw()
  
  
      def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())
  
  
  
  def main():
      app = QtWidgets.QApplication(sys.argv)
      w = PrettyWidget()
      sys.exit(app.exec_())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>I'm getting this warning: QWidget::setLayout: Attempting to set QLayout "" on PrettyWidget "", which already has a layout
  QCoreApplication::exec: The event loop is already running
  And also the widgets are overlapped,any help will be very much appreciated!</p>