Graphs - Navigation Tool Bar Not Showing Up
Graphs - Navigation Tool Bar Not Showing Up
(OP)
Finally starting to get around to making GUIs/graphs in python and I want to bring in the nice navigation tool bar that i have seen in the matplotlib "pacakge" (not sure if package is the right term?).
My code looks like the following taken from an example online with small modifications to bring in the navigation toolbar.
Above, I've highlighted in red the lines of code I've added. My graph looks like the following:

The navigation bar, from my understanding, would be at the top of the graph and look like:

Any ideas on where I went wrong?
Thanks!
My code looks like the following taken from an example online with small modifications to bring in the navigation toolbar.
CODE --> Python
import matplotlib.pyplot as plt
import random
class App(QMainWindow):
def __init__(self):
super().__init__()
self.left = 100
self.top = 100
self.title = 'PyQt5 matplotlib example - pythonspot.com'
self.width = 640
self.height = 400
self.initUI() #not sure what this line of code does
self.fig=Figure()
self.canvas=FigureCanvas(self.fig)
#add plot toolbar from matplotlib
self.toolbar = NavigationToolbar(self.canvas, self)
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
m = PlotCanvas(self, width=5, height=4)
m.move(0,0)
button = QPushButton('PyQt5 buttons', self)
button.setToolTip('This is an example button')
button.move(500,0)
button.resize(140,100)
self.show()
class PlotCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding,QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.plot()
def plot(self):
data = [random.random() for i in range(25)]
ax = self.figure.add_subplot(111)
ax.plot(data, 'r-')
ax.set_title('PyQt Matplotlib Example')
self.draw()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Above, I've highlighted in red the lines of code I've added. My graph looks like the following:

The navigation bar, from my understanding, would be at the top of the graph and look like:

Any ideas on where I went wrong?
Thanks!
S&T
RE: Graphs - Navigation Tool Bar Not Showing Up
This is the source of your code? https://pythonspot.com/pyqt5-matplotlib/
You need sys, PyQt, other matplotlib modules, etc.
As I look at the PyQt module, it seems to a require an account in order to install, which I am not willing to do. If you have that account, with all the appropriate modules installed, just double check your imports and go from there.
RE: Graphs - Navigation Tool Bar Not Showing Up
Check out the Embedding in QT page from matplotlib here: Link
Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering
RE: Graphs - Navigation Tool Bar Not Showing Up
CODE --> python
I have all the front end stuff and it runs with no errors. I'll try out your link when I get back home tonight Celt.
S&T
RE: Graphs - Navigation Tool Bar Not Showing Up
For the speed thing if you plan to keep plotting different data with the same number of points, like a beam shear diagram, I found populating the graph with a dummy data set and changing the x,y values of the set to be much faster than wiping out the data-set and creating a new one.
Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering