0

I need to know how to plot a graph using matplotlib in the main interface. I am using PyQt5. I was able to plot a simple graph on another window. When I use pycharm it shows the chart in a separate window. But I need to plot it on my main interface. Also I am trying to develop an app for rasberi pi, so I need to know how to plot the graph according to the data from serial read. Help me to fix. Thank you.

class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()

        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.ui.pushButtonGraph.clicked.connect(self.load_Data)


    def load_Data(self):
        x = [2, 4, 6, 8, 10]
        y = [6, 7, 8, 2, 10, ]

        plt.bar(x, y, label='Bar 1')

        plt.xlabel('x')
        plt.ylabel('y')
        plt.title('Graph test')
        plt.legend()
        plt.show()

1 Answers1

0

I think the problem may be that you added an extra comma at the end of your variable 'y'. Where it says...

y = [6, 7, 8, 2, 10, ]

I think it should say...

y = [6, 7, 8, 2, 10]

Let me know if that works!

killer croc
  • 70
  • 2
  • 12
  • It didnt work.. in this project i have a main interface. I need to plot the graph on that interface. Now it plots in another window – Chanuka Gayantha Feb 27 '19 at 12:05
  • Here is a post that does a good job explaining how to embed a plot in pyqt: https://stackoverflow.com/questions/12459811/how-to-embed-matplotlib-in-pyqt-for-dummies – killer croc Feb 27 '19 at 12:09