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()
0

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

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
Here is a post that does a good job explaining how to embed a plot in pyqt: stackoverflow.com/questions/12459811/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.