Wednesday, 15 January 2014

qt - Draw a vertical line with Matplotlib -


I would like to draw a vertical line with Matpotlib, I get this method: axvline but this work does not. Here is my code: importing sys import matplotlib matplotlib.use ('Qt4Agg') from plut class window (QtGui.QMainWindow, Ui_MainWindow) as matplotlib import PyQt4 import from pyplot ui_courbe from QtGui Import *: Def __init __ (self, parent = none): Super (window, self) .__ init __ (parent) self.setupUi (self) self.boutonDessiner.clicked.connect (self.generatePlot) def generatePlot ( Self): # plot ax = generate self.graphicsView.canvas.fig.add_subplot (111) ax.plot ([1,3,5,7], [2,5,1, -2]) plt.axvline (x = 4) self.graphicsView. Canvas.draw () if __name__ == '__main__': app = win QtGui.QApplication (sys.argv) = window (win.show) sys.exit (app.exec_ ())

I can see my plot but no vertical line. Why?

Regards,

Phillip

Your example self Not required, but I need to change you:

  with plt.axvline (x = 4)  

:

ax.axvline (x = 4)

You are adding the line to an axis that you are not showing plt. Using the is a pipeline interface that you probably want to avoid with GUI, then all your conspiracy has to go on axis like the ax.


No comments:

Post a Comment