The fit module provides an interactive curve fitting widget/dialog allowing:
  • to fit data manually (by moving sliders)
  • or automatically (with standard optimization algorithms provided by scipy).


import numpy as np

from import FitParam, guifit

def test():
    x = np.linspace(-10, 10, 1000)
    y = np.cos(1.5*x)+np.random.rand(x.shape[0])*.2
    def fit(x, params):
        a, b = params
        return np.cos(b*x)+a
    a = FitParam("Offset", 1., 0., 2.)
    b = FitParam("Frequency", 2., 1., 10., logscale=True)
    params = [a, b]
    values = guifit(x, y, fit, params, xlabel="Time (s)", ylabel="Power (a.u.)")
    print([param.value for param in params])

if __name__ == "__main__":

Reference, y, fitfunc, fitparams, fitargs=None, fitkwargs=None, wintitle=None, title=None, xlabel=None, ylabel=None, param_cols=1, auto_fit=True, winsize=None, winpos=None)[source]

GUI-based curve fitting tool

class, icon='guiqwt.svg', edit=True, toolbar=False, options=None, parent=None, panels=None, param_cols=1, legend_anchor='TR', auto_fit=False)[source]
class RenderFlags(QWidget.RenderFlags)

QWidget.RenderFlags(int) QWidget.RenderFlags()

FitDialog.acceptDrops(self) → bool

accepted(self) [signal]

FitDialog.accessibleDescription(self) → object
FitDialog.accessibleName(self) → object
FitDialog.actionEvent(self, QActionEvent)
FitDialog.actions(self) → object

Activate default tool

FitDialog.addAction(self, QAction)
FitDialog.addActions(self, object)

Register a panel to the plot manager

Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools
FitDialog.add_plot(plot, plot_id=<class 'guiqwt.plot.DefaultPlotID'>)
Register a plot to the plot manager:
  • plot: guiqwt.curve.CurvePlot or guiqwt.image.ImagePlot object
  • plot_id (default id is the plot object’s id: id(plot)): unique ID identifying the plot (any Python object), this ID will be asked by the manager to access this plot later.
Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools

Register a separator tool to the plot manager: the separator tool is just a tool which insert a separator in the plot context menu

FitDialog.add_tool(ToolKlass, *args, **kwargs)
Register a tool to the manager
  • ToolKlass: tool’s class (guiqwt builtin tools are defined in module
  • args: arguments sent to the tool’s class
  • kwargs: keyword arguments sent to the tool’s class
Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools
FitDialog.add_toolbar(toolbar, toolbar_id='default')
Add toolbar to the plot manager
toolbar: a QToolBar object toolbar_id: toolbar’s id (default id is string “default”)
FitDialog.autoFillBackground(self) → bool
FitDialog.backgroundRole(self) → QPalette.ColorRole
FitDialog.baseSize(self) → QSize
FitDialog.blockSignals(self, bool) → bool
FitDialog.changeEvent(self, QEvent)
FitDialog.childAt(self, QPoint) → QWidget

childAt(self, int, int) -> QWidget

FitDialog.childEvent(self, QChildEvent)
FitDialog.children(self) → object
FitDialog.childrenRect(self) → QRect
FitDialog.childrenRegion(self) → QRegion
FitDialog.close(self) → bool
FitDialog.closeEvent(self, QCloseEvent)
FitDialog.colorCount(self) → int

Call all the registred panels ‘configure_panel’ methods to finalize the object construction (this allows to use tools registered to the same plot manager as the panel itself with breaking the registration sequence: “add plots, then panels, then tools”)

FitDialog.connect(QObject, QT_SIGNAL, QObject, QT_SLOT_QT_SIGNAL, Qt.ConnectionType = Qt.AutoConnection) → object

connect(QObject, QT_SIGNAL, Callable[..., None], Qt.ConnectionType = Qt.AutoConnection) -> object connect(self, QObject, QT_SIGNAL, QT_SLOT_QT_SIGNAL, Qt.ConnectionType = Qt.AutoConnection) -> object

FitDialog.connectNotify(self, QT_SIGNAL)
FitDialog.contentsMargins(self) → QMargins
FitDialog.contentsRect(self) → QRect
FitDialog.contextMenuEvent(self, QContextMenuEvent)
FitDialog.contextMenuPolicy(self) → Qt.ContextMenuPolicy
FitDialog.create(self, window: int = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
FitDialog.create_action(title, triggered=None, toggled=None, shortcut=None, icon=None, tip=None, checkable=None, context=1, enabled=None)

Create a new QAction

FitDialog.cursor(self) → QCursor

customContextMenuRequested(self, QPoint) [signal]

FitDialog.customEvent(self, QEvent)
FitDialog.depth(self) → int
FitDialog.destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)

destroyed(self, QObject = None) [signal] destroyed(self) [signal]

FitDialog.devType(self) → int
FitDialog.disconnect(QObject, QT_SIGNAL, QObject, QT_SLOT_QT_SIGNAL) → object

disconnect(QObject, QT_SIGNAL, Callable[..., None]) -> object

FitDialog.disconnectNotify(self, QT_SIGNAL)
FitDialog.done(self, int)
FitDialog.dragEnterEvent(self, QDragEnterEvent)
FitDialog.dragLeaveEvent(self, QDragLeaveEvent)
FitDialog.dragMoveEvent(self, QDragMoveEvent)
FitDialog.dropEvent(self, QDropEvent)
FitDialog.dynamicPropertyNames(self) → object
FitDialog.effectiveWinId(self) → int
FitDialog.emit(self, QT_SIGNAL, *)
FitDialog.enabledChange(self, bool)
FitDialog.enterEvent(self, QEvent)
FitDialog.event(self, QEvent) → bool
FitDialog.eventFilter(self, QObject, QEvent) → bool
FitDialog.exec(self) → int
FitDialog.exec_(self) → int
FitDialog.extension(self) → QWidget
FitDialog.find(int) → QWidget
FitDialog.findChild(self, type, name: object = '') → object

findChild(self, Tuple, name: object = ‘’) -> object

FitDialog.findChildren(self, type, name: object = '') → List

findChildren(self, Tuple, name: object = ‘’) -> List findChildren(self, type, QRegExp) -> List findChildren(self, Tuple, QRegExp) -> List


finished(self, int) [signal]

FitDialog.focusInEvent(self, QFocusEvent)
FitDialog.focusNextChild(self) → bool
FitDialog.focusNextPrevChild(self, bool) → bool
FitDialog.focusOutEvent(self, QFocusEvent)
FitDialog.focusPolicy(self) → Qt.FocusPolicy
FitDialog.focusPreviousChild(self) → bool
FitDialog.focusProxy(self) → QWidget
FitDialog.focusWidget(self) → QWidget
FitDialog.font(self) → QFont
FitDialog.fontChange(self, QFont)
FitDialog.fontInfo(self) → QFontInfo
FitDialog.fontMetrics(self) → QFontMetrics
FitDialog.foregroundRole(self) → QPalette.ColorRole
FitDialog.frameGeometry(self) → QRect
FitDialog.frameSize(self) → QSize
FitDialog.geometry(self) → QRect
FitDialog.getContentsMargins(self) → Tuple[int, int, int, int]

Return the active plot

The active plot is the plot whose canvas has the focus otherwise it’s the “default” plot


Return active tool


Return widget context menu – built using active tools


Convenience function to get the contrast adjustment panel

Return None if the contrast adjustment panel has not been added to this manager


Return default plot

The default plot is the plot on which tools and panels will act.


Get default tool


Return default toolbar


Return fitargs and fitkwargs


Convenience function to get the item list panel

Return None if the item list panel has not been added to this manager


Return the main (parent) widget

Note that for py:class:guiqwt.plot.CurveWidget or guiqwt.plot.ImageWidget objects, this method will return the widget itself because the plot manager is integrated to it.


Return panel from its ID Panel IDs are listed in module guiqwt.panels

FitDialog.get_plot(plot_id=<class 'guiqwt.plot.DefaultPlotID'>)

Return plot associated to plot_id (if method is called without specifying the plot_id parameter, return the default plot)


Return all registered plots


Return tool instance from its class

Return toolbar from its ID
toolbar_id: toolbar’s id (default id is string “default”)

Convenience method to get fit parameter values


Convenience function to get the X-axis cross section panel

Return None if the X-axis cross section panel has not been added to this manager


Convenience function to get the Y-axis cross section panel

Return None if the Y-axis cross section panel has not been added to this manager

FitDialog.grabGesture(self, Qt.GestureType, flags: Qt.GestureFlags = Qt.GestureFlags(0))

grabMouse(self, QCursor)

FitDialog.grabShortcut(self, QKeySequence, context: Qt.ShortcutContext = Qt.WindowShortcut) → int
FitDialog.graphicsEffect(self) → QGraphicsEffect
FitDialog.graphicsProxyWidget(self) → QGraphicsProxyWidget
FitDialog.handle(self) → int
FitDialog.hasFocus(self) → bool
FitDialog.hasMouseTracking(self) → bool
FitDialog.height(self) → int
FitDialog.heightForWidth(self, int) → int
FitDialog.heightMM(self) → int
FitDialog.hideEvent(self, QHideEvent)
FitDialog.inherits(self, str) → bool
FitDialog.inputContext(self) → QInputContext
FitDialog.inputMethodEvent(self, QInputMethodEvent)
FitDialog.inputMethodHints(self) → Qt.InputMethodHints
FitDialog.inputMethodQuery(self, Qt.InputMethodQuery) → object
FitDialog.insertAction(self, QAction, QAction)
FitDialog.insertActions(self, QAction, object)
FitDialog.installEventFilter(self, QObject)
FitDialog.isActiveWindow(self) → bool
FitDialog.isAncestorOf(self, QWidget) → bool
FitDialog.isEnabled(self) → bool
FitDialog.isEnabledTo(self, QWidget) → bool
FitDialog.isEnabledToTLW(self) → bool
FitDialog.isFullScreen(self) → bool
FitDialog.isHidden(self) → bool
FitDialog.isLeftToRight(self) → bool
FitDialog.isMaximized(self) → bool
FitDialog.isMinimized(self) → bool
FitDialog.isModal(self) → bool
FitDialog.isRightToLeft(self) → bool
FitDialog.isSizeGripEnabled(self) → bool
FitDialog.isTopLevel(self) → bool
FitDialog.isVisible(self) → bool
FitDialog.isVisibleTo(self, QWidget) → bool
FitDialog.isWidgetType(self) → bool
FitDialog.isWindow(self) → bool
FitDialog.isWindowModified(self) → bool
FitDialog.keyPressEvent(self, QKeyEvent)
FitDialog.keyReleaseEvent(self, QKeyEvent)
FitDialog.keyboardGrabber() → QWidget
FitDialog.killTimer(self, int)
FitDialog.layout(self) → QLayout
FitDialog.layoutDirection(self) → Qt.LayoutDirection
FitDialog.leaveEvent(self, QEvent)
FitDialog.locale(self) → QLocale
FitDialog.logicalDpiX(self) → int
FitDialog.logicalDpiY(self) → int
FitDialog.mapFrom(self, QWidget, QPoint) → QPoint
FitDialog.mapFromGlobal(self, QPoint) → QPoint
FitDialog.mapFromParent(self, QPoint) → QPoint
FitDialog.mapTo(self, QWidget, QPoint) → QPoint
FitDialog.mapToGlobal(self, QPoint) → QPoint
FitDialog.mapToParent(self, QPoint) → QPoint
FitDialog.mask(self) → QRegion
FitDialog.maximumHeight(self) → int
FitDialog.maximumSize(self) → QSize
FitDialog.maximumWidth(self) → int
FitDialog.metaObject(self) → QMetaObject
FitDialog.metric(self, QPaintDevice.PaintDeviceMetric) → int
FitDialog.minimumHeight(self) → int
FitDialog.minimumSize(self) → QSize
FitDialog.minimumSizeHint(self) → QSize
FitDialog.minimumWidth(self) → int
FitDialog.mouseDoubleClickEvent(self, QMouseEvent)
FitDialog.mouseGrabber() → QWidget
FitDialog.mouseMoveEvent(self, QMouseEvent)
FitDialog.mousePressEvent(self, QMouseEvent)
FitDialog.mouseReleaseEvent(self, QMouseEvent)
FitDialog.move(self, QPoint)

move(self, int, int)

FitDialog.moveEvent(self, QMoveEvent)
FitDialog.moveToThread(self, QThread)
FitDialog.nativeParentWidget(self) → QWidget
FitDialog.nextInFocusChain(self) → QWidget
FitDialog.normalGeometry(self) → QRect
FitDialog.numColors(self) → int
FitDialog.objectName(self) → object
FitDialog.orientation(self) → Qt.Orientation
FitDialog.overrideWindowFlags(self, Qt.WindowFlags)
FitDialog.overrideWindowState(self, Qt.WindowStates)
FitDialog.paintEngine(self) → QPaintEngine
FitDialog.paintEvent(self, QPaintEvent)
FitDialog.paintingActive(self) → bool
FitDialog.palette(self) → QPalette
FitDialog.paletteChange(self, QPalette)
FitDialog.parent(self) → QObject
FitDialog.parentWidget(self) → QWidget
FitDialog.physicalDpiX(self) → int
FitDialog.physicalDpiY(self) → int
FitDialog.pos(self) → QPoint
FitDialog.previousInFocusChain(self) → QWidget, str) → object

Each keyword argument is either the name of a Qt property or a Qt signal. For properties the property is set to the given value which should be of an appropriate type. For signals the signal is connected to the given value which should be a callable.

FitDialog.receivers(self, QT_SIGNAL) → int
FitDialog.rect(self) → QRect

Refresh Fit Tool dialog box


Register standard, curve-related and other tools


Register standard, image-related and other tools


Register only curve-related tools


Register only image-related tools


Register other common tools


Registering basic tools for standard plot dialog –> top of the context-menu


Register the plotting dialog box tools: the base implementation provides standard, curve-related and other tools - i.e. calling this method is exactly the same as calling guiqwt.plot.CurveDialog.register_all_curve_tools()

This method may be overriden to provide a fully customized set of tools


rejected(self) [signal]

FitDialog.releaseShortcut(self, int)
FitDialog.removeAction(self, QAction)
FitDialog.removeEventFilter(self, QObject)
FitDialog.render(self, QPaintDevice, targetOffset: QPoint = QPoint(), sourceRegion: QRegion = QRegion(), flags: QWidget.RenderFlags = QWidget.DrawWindowBackground|QWidget.DrawChildren)

render(self, QPainter, targetOffset: QPoint = QPoint(), sourceRegion: QRegion = QRegion(), flags: QWidget.RenderFlags = QWidget.DrawWindowBackground|QWidget.DrawChildren)


repaint(self, int, int, int, int) repaint(self, QRect) repaint(self, QRegion)

FitDialog.resize(self, QSize)

resize(self, int, int)

FitDialog.resizeEvent(self, QResizeEvent)
FitDialog.restoreGeometry(self, QByteArray) → bool
FitDialog.result(self) → int
FitDialog.saveGeometry(self) → QByteArray
FitDialog.scroll(self, int, int)

scroll(self, int, int, QRect)

FitDialog.sender(self) → QObject
FitDialog.senderSignalIndex(self) → int
FitDialog.setAcceptDrops(self, bool)
FitDialog.setAccessibleDescription(self, object)
FitDialog.setAccessibleName(self, object)
FitDialog.setAttribute(self, Qt.WidgetAttribute, on: bool = True)
FitDialog.setAutoFillBackground(self, bool)
FitDialog.setBackgroundRole(self, QPalette.ColorRole)
FitDialog.setBaseSize(self, int, int)

setBaseSize(self, QSize)

FitDialog.setContentsMargins(self, int, int, int, int)

setContentsMargins(self, QMargins)

FitDialog.setContextMenuPolicy(self, Qt.ContextMenuPolicy)
FitDialog.setCursor(self, QCursor)
FitDialog.setDisabled(self, bool)
FitDialog.setEnabled(self, bool)
FitDialog.setExtension(self, QWidget)
FitDialog.setFixedHeight(self, int)
FitDialog.setFixedSize(self, QSize)

setFixedSize(self, int, int)

FitDialog.setFixedWidth(self, int)

setFocus(self, Qt.FocusReason)

FitDialog.setFocusPolicy(self, Qt.FocusPolicy)
FitDialog.setFocusProxy(self, QWidget)
FitDialog.setFont(self, QFont)
FitDialog.setForegroundRole(self, QPalette.ColorRole)
FitDialog.setGeometry(self, QRect)

setGeometry(self, int, int, int, int)

FitDialog.setGraphicsEffect(self, QGraphicsEffect)
FitDialog.setHidden(self, bool)
FitDialog.setInputContext(self, QInputContext)
FitDialog.setInputMethodHints(self, Qt.InputMethodHints)
FitDialog.setLayout(self, QLayout)
FitDialog.setLayoutDirection(self, Qt.LayoutDirection)
FitDialog.setLocale(self, QLocale)
FitDialog.setMask(self, QBitmap)

setMask(self, QRegion)

FitDialog.setMaximumHeight(self, int)
FitDialog.setMaximumSize(self, int, int)

setMaximumSize(self, QSize)

FitDialog.setMaximumWidth(self, int)
FitDialog.setMinimumHeight(self, int)
FitDialog.setMinimumSize(self, int, int)

setMinimumSize(self, QSize)

FitDialog.setMinimumWidth(self, int)
FitDialog.setModal(self, bool)
FitDialog.setMouseTracking(self, bool)
FitDialog.setObjectName(self, object)
FitDialog.setOrientation(self, Qt.Orientation)
FitDialog.setPalette(self, QPalette)
FitDialog.setParent(self, QWidget)

setParent(self, QWidget, Qt.WindowFlags)

FitDialog.setProperty(self, str, object) → bool
FitDialog.setResult(self, int)
FitDialog.setShortcutAutoRepeat(self, int, enabled: bool = True)
FitDialog.setShortcutEnabled(self, int, enabled: bool = True)
FitDialog.setShown(self, bool)
FitDialog.setSizeGripEnabled(self, bool)
FitDialog.setSizeIncrement(self, int, int)

setSizeIncrement(self, QSize)

FitDialog.setSizePolicy(self, QSizePolicy)

setSizePolicy(self, QSizePolicy.Policy, QSizePolicy.Policy)

FitDialog.setStatusTip(self, object)
FitDialog.setStyle(self, QStyle)
FitDialog.setStyleSheet(self, object)
FitDialog.setTabOrder(QWidget, QWidget)
FitDialog.setToolTip(self, object)
FitDialog.setUpdatesEnabled(self, bool)
FitDialog.setVisible(self, bool)
FitDialog.setWhatsThis(self, object)
FitDialog.setWindowFilePath(self, object)
FitDialog.setWindowFlags(self, Qt.WindowFlags)
FitDialog.setWindowIcon(self, QIcon)
FitDialog.setWindowIconText(self, object)
FitDialog.setWindowModality(self, Qt.WindowModality)
FitDialog.setWindowModified(self, bool)
FitDialog.setWindowOpacity(self, float)
FitDialog.setWindowRole(self, object)
FitDialog.setWindowState(self, Qt.WindowStates)
FitDialog.setWindowTitle(self, object)

Set active tool (if tool argument is None, the active tool will be the default tool)

FitDialog.set_contrast_range(zmin, zmax)

Convenience function to set the contrast adjustment panel range

This is strictly equivalent to the following:

# Here, *widget* is for example a CurveWidget instance
# (the same apply for CurvePlot, ImageWidget, ImagePlot or any 
#  class deriving from PlotManager)
widget.get_contrast_panel().set_range(zmin, zmax)

Set default plot

The default plot is the plot on which tools and panels will act.


Set default tool


Set default toolbar
FitDialog.showEvent(self, QShowEvent)
FitDialog.showExtension(self, bool)
FitDialog.signalsBlocked(self) → bool
FitDialog.size(self) → QSize
FitDialog.sizeHint(self) → QSize
FitDialog.sizeIncrement(self) → QSize
FitDialog.sizePolicy(self) → QSizePolicy
FitDialog.stackUnder(self, QWidget)
FitDialog.startTimer(self, int) → int
FitDialog.statusTip(self) → object → QStyle
FitDialog.styleSheet(self) → object
FitDialog.tabletEvent(self, QTabletEvent)
FitDialog.testAttribute(self, Qt.WidgetAttribute) → bool
FitDialog.thread(self) → QThread
FitDialog.timerEvent(self, QTimerEvent)
FitDialog.toolTip(self) → object
FitDialog.topLevelWidget(self) → QWidget, object, disambiguation: str = None, n: int = -1) → object
FitDialog.trUtf8(self, object, disambiguation: str = None, n: int = -1) → object
FitDialog.underMouse(self) → bool
FitDialog.ungrabGesture(self, Qt.GestureType)

update(self, QRect) update(self, QRegion) update(self, int, int, int, int)


Convenience function to update the cross section panels at once

This is strictly equivalent to the following:

# Here, *widget* is for example a CurveWidget instance
# (the same apply for CurvePlot, ImageWidget, ImagePlot or any 
#  class deriving from PlotManager)

Update tools for current plot

FitDialog.updatesEnabled(self) → bool
FitDialog.visibleRegion(self) → QRegion
FitDialog.whatsThis(self) → object
FitDialog.wheelEvent(self, QWheelEvent)
FitDialog.width(self) → int
FitDialog.widthMM(self) → int
FitDialog.winId(self) → int
FitDialog.window(self) → QWidget
FitDialog.windowActivationChange(self, bool)
FitDialog.windowFilePath(self) → object
FitDialog.windowFlags(self) → Qt.WindowFlags
FitDialog.windowIcon(self) → QIcon
FitDialog.windowIconText(self) → object
FitDialog.windowModality(self) → Qt.WindowModality
FitDialog.windowOpacity(self) → float
FitDialog.windowRole(self) → object
FitDialog.windowState(self) → Qt.WindowStates
FitDialog.windowTitle(self) → object
FitDialog.windowType(self) → Qt.WindowType
FitDialog.x(self) → int
FitDialog.x11Info(self) → QX11Info
FitDialog.x11PictureHandle(self) → int
FitDialog.y(self) → int
class, value, min, max, logscale=False, steps=5000, format='%.3f', size_offset=0, unit='')[source]

Return a copy of this fitparam

class, comment=None, icon='')[source]

helper function that passes the visitor to the accept methods of all the items in this dataset


Check the dataset item values

edit(parent=None, apply=None, size=None)
Open a dialog box to edit data set
  • parent: parent widget (default is None, meaning no parent)
  • apply: apply callback (default is None)
  • size: dialog size (QSize object or integer tuple (width, height))

Return data set comment


Return data set icon


Return data set title


Set default values


Edit data set with text input only

to_string(debug=False, indent=None, align=False)

Return readable string representation of the data set If debug is True, add more details on data items

view(parent=None, size=None)
Open a dialog box to view data set
  • parent: parent widget (default is None, meaning no parent)
  • size: dialog size (QSize object or integer tuple (width, height))