python - use a matplotlib Figure in PyQt -
programming noob here. i'm trying use matplotlib widget in pyqt4 gui. widget similar matplotlib's example qt.
at point user needs click on plot, thought ginput() handle. however, doesn't work because figure doesn't have manager (see below). note similar another question never got answered.
attributeerror: 'nonetype' object has no attribute 'manager' figure.show works figures managed pyplot, created pyplot.figure().
i'm assuming "normally" there's way around this.
another simple script demonstrate:
from __future__ import print_function matplotlib.figure import figure import numpy np import matplotlib.pyplot plt x = np.arange(0, 5, 0.1) y = np.sin(x) # figure creation plt (also given manager, although not explicitly) plt.figure() plt.plot(x,y) coords = plt.ginput() # click on axes somewhere; works print(coords) # figure creation w/o plt manualfig = figure() manualaxes = manualfig.add_subplot(111) manualaxes.plot(x,y) manualfig.show() # fail because of no manager, yet shown method manualcoords = manualfig.ginput() # comment out above , fails print(manualcoords)
as popular pyplot (i can't hardly find answer without it), doesn't seem play nice when working gui. thought pyplot wrapper oo framework guess i'm noob.
my question this: there way attach pyplot instance of matplotlib.figure.figure? there easy way attach manager figure? found new_figure_manager() in matplotlib.backends.backend_qt4agg, couldn't work, if right solution.
many thanks,
james
pyplot
wrapper oo interface, lot of work read example link again carefully,
figurecanvas.__init__(self, fig)
line important tells figure canvas use. figure
object collection of axes
objects (and few text
objects), canvas
object knows how turn artist
objects (ie matplotlib's internal representation of lines, text, points, etc) in pretty colors. see something wrote embedding example not sub-class figurecanvas
.
there pr make process easier, stalled while 1.4 out door.
also see: which recommended way plot: matplotlib or pylab?, how can attach pyplot function figure instance?
Comments
Post a Comment