python - lmfit, result.plot_fit(ax) not plotting all 3 plots in pyqt -


i have pyqt5 widget

class mplibwidget(qtwidgets.qwidget): """ base matplotlib widget """ def __init__(self, parent=none):     super(mplibwidget, self).__init__(parent)      self.figure = figure()     self.canvas = figurecanvasqtagg(self.figure)     self.canvas.setparent(self)      self.mpl_toolbar = navigationtoolbar2qt(self.canvas, self)      self.canvas.mpl_connect('key_press_event', self.on_key_press)      self.axes = self.figure.add_subplot(111)     self.axes.hold(false) 

when try use fit using result.plot_fit(ax=ax), plots data column of plot fit. not init_fit or best_fit.

def fit(self, data, widget):     self.layers = ['air', 'bk7', 'slg']     wv = np.arange(400, 900)     mod = lmfit.model(self.get_r, ['wavelengths'], ['thickness', 'void_percent'])     mod.set_param_hint('thickness', value=130, min=50, max=250)     mod.set_param_hint('void_percent', value=.15, min=.05, max=.5)      r = data.norm(wv)     result = mod.fit(r, wavelengths=wv)      rmse = (sp.sum(result.residual**2)/(result.residual.size-2))**0.5     bf_values = result.best_values     bf_str = 'thk: ' + str(round(bf_values['thickness'])) + ", void %: " + str(round(bf_values['void_percent']*100, 2))     txt_spot = wv.min()-100 + (wv.max()-wv.min()) / 2      ax = widget.figure.axes[0]     result.plot_fit(ax=ax, datafmt='b+', initfmt='r--', fitfmt='g-')     ax.text(txt_spot, .9, "rmse: "+str(round(rmse, 3)))     ax.text(txt_spot, .85, bf_str)     widget.canvas.draw() 

if don't use (ax=ax) , plot_fit(), plt.show() plots 3 axes fine opens new window. want plot show in widget inside program.

inside widget ax=ax inside widget plot_fit(ax=ax) outside widget fit outside widget plot_fit(); plt.show()

the problem in self.axes.hold(false) line clears figure before each call plot , like. plot_fit last line plotted 'data', hence data line.

do not use hold(false) in general, thinking of removing upstream.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -